Results 1 to 5 of 5

Thread: Is it safe to sendEvent to MainWIndow from thread?and postEvent?

  1. #1
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Is it safe to sendEvent to MainWIndow from thread?and postEvent?

    I transfer the MainWindow's pointer to a thread,and in the thread I call send event to this
    window.In fact, after a while sendEvent don't return.I know in thread had better not call any GUI funtion, and i know sendEvent only return after the message is processed too.
    Thanks a lot!

  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: Is it safe to sendEvent to MainWIndow from thread?and postEvent?

    SendEvent is not thread safe, as it is a synchronic call. PostEvent should work fine.

  3. The following user says thank you to wysota for this useful post:

    coralbird (24th July 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Is it safe to sendEvent to MainWIndow from thread?and postEvent?

    Quote Originally Posted by wysota
    SendEvent is not thread safe, as it is a synchronic call. PostEvent should work fine.
    Thanks.
    Is it certain that the event that sent by postEvent can be processed?what I mean is "message lost". Is it processed as the sequence that events be sent?
    Thanks a lot!

  5. #4
    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: Is it safe to sendEvent to MainWIndow from thread?and postEvent?

    Quote Originally Posted by coralbird
    Is it certain that the event that sent by postEvent can be processed?
    Yes, provided that you posted it correctly.

    what I mean is "message lost".
    Maybe it got lost somewhere during the process of posting? Did you remember to create it on heap? Could you show the lines where you post the event? If it is a custom event, did you reimplement the method for handling custom events in the target widget?

    Is it processed as the sequence that events be sent?
    In general -- yes.

  6. The following user says thank you to wysota for this useful post:

    coralbird (26th July 2006)

  7. #5
    Join Date
    Jan 2006
    Posts
    55
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: Is it safe to sendEvent to MainWIndow from thread?and postEvent?

    Quote Originally Posted by wysota
    Maybe it got lost somewhere during the process of posting?
    In fact I don't find message lost , I just worry if postEvent is reliable to use.And I prepare to do strict test .

    Quote Originally Posted by wysota
    Did you remember to create it on heap? Could you show the lines where you post the event? If it is a custom event, did you reimplement the method for handling custom events in the target widget?
    All of the answer is sure.Now the code is working fine.
    Thank wysota again!

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.