Results 1 to 4 of 4

Thread: WaitForSingleObject

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default WaitForSingleObject

    Hi,

    I'm developing and application that uses a DAQ(Digital Acquisition) Card on Windows.
    In the sample examples there is this piece of code:
    Qt Code:
    1. IntThread(void* pArg)
    2. {
    3. while (1) {
    4. if (WaitForSingleObject(hEvent[0], INFINITE) == WAIT_OBJECT_0) {
    5. int_count++;
    6. ResetEvent(hEvent[0]);
    7. InvalidateRect(hMainWnd, NULL, FALSE);
    8. }
    9. }
    10. _endthread();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I don't understand how to reimplement the "WaitForSingleObject" function.
    As I understand, the DAQ card driver sends an event that is catched on this function, so maybe is the only way to get the driver event processed?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: WaitForSingleObject

    Basically what WaitForSingleObject() does is that it tells the operating system to put the process to sleep until something happens. This "something" decides on the semantics of the call. It can be a semaphore but probably also a socket or a bunch of other things that can be "waited for". So it all boils down to what hEvent[0] really is and whether you can get access to it in a non-blocking fashion.
    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
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WaitForSingleObject

    Hi,

    hEvent is initialized by a DAQ function call:
    Qt Code:
    1. I16 DIO_SetDualInterrupt (U16 CardNumber, I16 Int1Mode, I16 Int2Mode, HANDLE *hEvent)
    To copy to clipboard, switch view to plain text mode 

    I think that what happens is that the driver comunicates to the operating system that there was an event and the OS is the one that wake up the calling process.
    So really, there is no other way to solve this without using this function.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: WaitForSingleObject

    Use QWinEventNotifier class instead of WaitForSingleObject

  5. The following user says thank you to kuzulis for this useful post:

    ^NyAw^ (13th February 2012)

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.