Results 1 to 6 of 6

Thread: Handler thread to process messages asynchronously

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Handler thread to process messages asynchronously

    Yes, like that.

    So your constructor would be like so:

    Qt Code:
    1. myEvent::myEvent(int yourData) : QEvent(QEvent::User)
    2. {
    3. this->yourData = yourData; // etc...
    4. }
    To copy to clipboard, switch view to plain text mode 

    and then:

    Qt Code:
    1. bool myThread::event( QEvent * e )
    2. {
    3. if (e->type() >= QEvent::User)
    4. {
    5. myEvent *e = static_cast<myEvent*>(e);
    6. (...)
    To copy to clipboard, switch view to plain text mode 

    As stated in the documentation, you must not access the object again once it has been posted:

    The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to access the event after it has been posted.
    Last edited by squidge; 24th April 2011 at 15:12.

  2. The following user says thank you to squidge for this useful post:

    Luc4 (24th April 2011)

Similar Threads

  1. creating widgets asynchronously
    By tampstaffs in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2009, 10:30
  2. How to communicate Qt Process with non-qt process
    By nrabara in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 15th February 2009, 21:01
  3. Asynchronously playing a sound (.wav) on windows mobile
    By TMan in forum Qt for Embedded and Mobile
    Replies: 10
    Last Post: 20th October 2008, 19:16
  4. GUI Thread getting no time to process
    By steg90 in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2007, 09:29
  5. Qt4 no debug messages
    By TheKedge in forum Newbie
    Replies: 3
    Last Post: 23rd January 2006, 17:52

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
  •  
Qt is a trademark of The Qt Company.