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?
Servers for Qt installer are currently down

How to get HANDLE in QT Project?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 315 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 13 Dec 2021, 08:44 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();
    
    J 1 Reply Last reply 13 Dec 2021, 08:53
    0
    • Q qwe3
      13 Dec 2021, 08:44

      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();
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 13 Dec 2021, 08:53 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 13 Dec 2021, 08:54 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

        1/3

        13 Dec 2021, 08:44

        • Login

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