Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qmessagebox throw excepton
Forum Update on Monday, May 27th 2025

Qmessagebox throw excepton

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mehdi.nine
    wrote on 2 Jul 2013, 12:59 last edited by
    #1

    Hi, i have a thread. in that i wrote:
    QMessageBox::information(0,"ss","ss");
    but it has following error:
    !http://upload7.ir/images/03962076836726290781.jpg(Error)!
    any idea?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 2 Jul 2013, 13:25 last edited by
      #2

      yep...don't use QMessageBox outside of gui thread ;)
      open the QMessageBox in a slot in the gui thread and call it with a queued connection signal.

      Edit. this doesn't even need to be the reason for the crash. Can you run the application in your IDE (in debug mode) and check the crash again?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mehdi.nine
        wrote on 2 Jul 2013, 13:53 last edited by
        #3

        on QMessageBox it throw exception. can you explain more how can i fix that?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 2 Jul 2013, 14:01 last edited by
          #4

          as i said... create a slot which shows the message box in the gui thread.
          Meaning create the slot for example in your main window:

          @
          void MyMainWindow::showInformation(...) //SLOT
          {
          QMessageBox::information(this, ...);
          }
          @

          Then create in your thread class:
          @
          class MyThread : public QThread
          {
          public:
          MyThread() { ... }

          signals:
          void showInfoBox(...);

          protected:
          virtual void run()
          {
          ....
          emit showInfoBox(...);
          ....
          }
          }
          @

          and where you create your thread object (assuming in your main window class):
          @
          MyThread* myThread = new MyThread;
          connect(myThread, SIGNAL(showInfoBox(...)), this, SLOT(showInformation(...)), Qt::QueuedConnection);
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mehdi.nine
            wrote on 2 Jul 2013, 14:17 last edited by
            #5

            thanks. i will try that.

            1 Reply Last reply
            0

            1/5

            2 Jul 2013, 12:59

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved