Results 1 to 4 of 4

Thread: How to wait for events produced by non-Qt threads?

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question How to wait for events produced by non-Qt threads?

    I inherited qthread and in the run() I delared two HANDLEs and asked an outside library to fill them with event(s) then run some non-qt threads that ends by emitting these events.

    When I was using non-qt threads I can simply call waitformultipleobjects() to wait for the return of these outside threads, but now whenever I call waitformultipleobjects() the qthread crashes.

    Any idea why this happens? I suspect it's because QApplication converts the two events to QEvents, but how am I supposed to handle these kind of QEvents? Or can I declare QEvents and hand QEvents to the outside thread as HANDLEs?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to wait for events produced by non-Qt threads?

    Does this QThread inheirted thread do something besides waiting for those native events?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to wait for events produced by non-Qt threads?

    nothing while waiting. actually I am using double buffer to receive pictures from a camera. Its sdk posts an event when a picture finishes to be sent to a buffer.
    the working loop is like this:
    Qt Code:
    1. for (int k = 0; k<8; k++)
    2. {
    3. //double buffer
    4. ready=WaitForMultipleObjects(2,hEvents,false,2000);
    5. if (ready==WAIT_OBJECT_0)
    6. {
    7. PCO_AddBufferEx(hCam,0,0,sBufNr1, xRes, yRes, 0x000e);
    8. for (int l = 0; l<xRes * yRes; l++)bitMap[l+mapOffset] = data1[l];
    9. Update();
    10. }
    11. else
    12. {
    13. if(ready==(WAIT_OBJECT_0+1))
    14. {
    15. PCO_AddBufferEx(hCam,0,0,sBufNr2, xRes, yRes, 0x000e);
    16. SetPort(false);
    17. for (int l = 0; l<xRes * yRes; l++)bitMap[l+mapOffset] = data2[l];
    18. Update();
    19. }
    20. else{
    21. PCO_SetRecordingState(hCam,0);
    22. abort = true;
    23. }
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to wait for events produced by non-Qt threads?

    If nothing else then maybe you don't need it at all?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.