Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get HANDLE in QT Project?
Forum Updated to NodeBB v4.3 + New Features

How to get HANDLE in QT Project?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 344 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by qwe3
    #1

    Hi,

    I have two threads: mainThread and one for heavy calculations. I would like to use CancelSynchronousIo ( winapi ) in main thread, but I need HANDLE from second thread.

    In second thread I have simple object. And I tried in this simpleObject something like that:

    void simpleClass::getHandle()   // this is slot in simpleObject, which is in the second thread
    {
       emit handleFromSecondThread(GetCurrentThread());
    }
    

    But when I check the value from GetCurrentThread(), I see that in mainThread and in secondThread this value is the same... How to get the correct value from second thread?

    Of course I did:

       thread = new QThread(this);
       simpleObject = simpleClass;
       simpleObject->moveToThread(thread);
       thread->start();
    
    jsulmJ 1 Reply Last reply
    0
    • Q qwe3

      Hi,

      I have two threads: mainThread and one for heavy calculations. I would like to use CancelSynchronousIo ( winapi ) in main thread, but I need HANDLE from second thread.

      In second thread I have simple object. And I tried in this simpleObject something like that:

      void simpleClass::getHandle()   // this is slot in simpleObject, which is in the second thread
      {
         emit handleFromSecondThread(GetCurrentThread());
      }
      

      But when I check the value from GetCurrentThread(), I see that in mainThread and in secondThread this value is the same... How to get the correct value from second thread?

      Of course I did:

         thread = new QThread(this);
         simpleObject = simpleClass;
         simpleObject->moveToThread(thread);
         thread->start();
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qwe3 said in How to get HANDLE in QT Project?:

      void simpleClass::getHandle()

      I guess you call getHandle() from first thread - is this right?
      If so it will, of course return handle from first thread.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qwe3
        wrote on last edited by qwe3
        #3

        @jsulm In mainThread I have connect like this:

        connect(this, &MainWindow::getId, simpleObject , &simpleClass::getHandle);
        

        EDIT
        And I send to simpleObject signal getId(). Of course I did:

           simpleObject->moveToThread(thread);
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved