Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Qmessagebox throw excepton

    General and Desktop
    2
    5
    1847
    Loading More Posts
    • 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
      mehdi.nine last edited by

      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 Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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 Reply Quote 0
        • M
          mehdi.nine last edited by

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

          1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            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 Reply Quote 0
            • M
              mehdi.nine last edited by

              thanks. i will try that.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post