Results 1 to 2 of 2

Thread: postEvent thread problem

  1. #1

    Default postEvent thread problem

    Hello,

    I’m having a problem with posting events to the GUI thread of mainwindow.

    This is my setup:
    I have several pieces of hardware that signal events through an old-style callback function (each of them is living in his own thread).

    This callback function does a
    Qt Code:
    1. QApplication::postEvent(mainwindow, customevent);
    To copy to clipboard, switch view to plain text mode 

    In the customevent handler of the mainwindow I pop up a standard (blocking) messagebox. This works fine until I connect more than one device.

    I would have expected the event loop of mainwindow to process the events in sequence, but it doesn’t. It looks like that for each postevent I do from the callback, a new event loop (or thread) is created.
    My understanding was that the posted events would be added to the queue of the main event loop of the receiver you specify in the call to postevent.

    Is there another way that I can post events to a receiver (from different threads) and be sure they will be handled in sequence?

    Kind Regards,
    Jeroen

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: postEvent thread problem

    Actually it's not an extra thread, but just a nested event loop. QMessageBox is a modal dialog which runs its own event loop. Once the message box is closed, execution returns to the "main" event loop. These both event loops are running in the same thread and all events gets processed meanwhile either event loop is running.
    J-P Nurmi

Similar Threads

  1. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. Replies: 11
    Last Post: 7th July 2006, 13:09

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.