Results 1 to 2 of 2

Thread: QMessageBox from QtConcurrent::run

  1. #1
    Join Date
    Mar 2009
    Location
    India
    Posts
    8
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QMessageBox from QtConcurrent::run

    I am trying to call a message box from a multi threaded loop. My loop is running in a function (ReadThread) that called from the QtConcurrent::run. In that function the application is continue sly reading a hardware device. I want to pop up a message box based on the hardware response.

    How I can call a message box from ReadThread() function?

    Qt Code:
    1. m_Future->waitForFinished();
    2. *m_Future = QtConcurrent::run(this, &MainWindow::ReadThread);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMessageBox from QtConcurrent::run

    All GUI operations, such as displaying a message box, must be executed by the same thread (which is often called the GUI thread). This is a limitation, not only of Qt, but also of all other widget toolkits I know of.

    You must not directly display the message box from your ReadThread function. However, what you can do is send some kind of notification to the GUI thread that will make it display the message box. This can be achieved with QMetaObject::invokeMethod(), for instance; add a slot to your main window and invoke it from ReadThread with QMetaObject::invokeMethod(); in the slot, display the message box. You can add parameters to the slot, e.g. values to display in the message box.

    Keep in mind that a message box blocks all user interaction. Surely you don't want the user to be spammed by thousands of message boxes triggered by your code running in a loop.

Similar Threads

  1. QtConcurrent and QSqlQuery
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2013, 14:28
  2. problems with QtConcurrent
    By Qtonimo in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2012, 10:51
  3. qtconcurrent
    By knishaq in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2009, 08:41
  4. QtConcurrent and QPainter
    By AwDogsgo2Heaven in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 08:35
  5. QtConcurrent
    By Brandybuck in forum An Introduction to QThreads
    Replies: 2
    Last Post: 9th May 2008, 14:10

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.