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. stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread
Forum Updated to NodeBB v4.3 + New Features

stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.0k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread.
    (unhandled exception at 0x...(Qt5Guid.dll) in my.exe)

    1. how to write try catch in the slotShowMsgbox(), in order to take care of stack overflow;
    2. is there any way to avoid stackoverflow? should i new QMessagebox? and how to delete it?
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You need to show us the code, otherwise we can only guess. The connection, signal emission and the slot.

      (Z(:^

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        void signalShowMsgbox(const QString&, const QString&);
        void slotShowMsgbox(const QString& title, const QString&text)
        {
        QMessageBox::critical(NULL, title, text);
        }
        connect signal & slot use Qt::AutoConnection;
        the signal is emitted in not-mainThread;
        slot is in mainThread because Qt ui(messagebox) must be in MainThread.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Set the connection to Qt::QueuedConnection explicitly. It probably won't help, but is worth a try.

          By "many" you mean how many messages do you pop up, actually? Perhaps it would be a good idea to rethink that design and group some messages together? Having to close many popups can be annoying to your users.

          (Z(:^

          1 Reply Last reply
          2
          • O Offline
            O Offline
            opengpu2
            wrote on last edited by
            #5

            well, the count is not certain, may be 30, 40, or even more...depends on the users transactions.
            yes, ur advice is good, i should not pop up so many Msgbox continuelly in a short time.
            However, as for now, what should i do to avoid Crash when met this stackoverflow?
            can i catch this exception(@Qt5Guid.dll), and just ignore it ?

            jsulmJ 1 Reply Last reply
            0
            • O opengpu2

              well, the count is not certain, may be 30, 40, or even more...depends on the users transactions.
              yes, ur advice is good, i should not pop up so many Msgbox continuelly in a short time.
              However, as for now, what should i do to avoid Crash when met this stackoverflow?
              can i catch this exception(@Qt5Guid.dll), and just ignore it ?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @opengpu2 Did you use Qt::QueuedConnection as suggested by @sierdzio ?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • O Offline
                O Offline
                opengpu2
                wrote on last edited by
                #7

                while signal and slot are no in the same thread, isn't AutoConn==QueuedConn??

                sierdzioS 1 Reply Last reply
                0
                • O opengpu2

                  while signal and slot are no in the same thread, isn't AutoConn==QueuedConn??

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @opengpu2 said in stack overflow when pop many QMessagebox in slot in mainthread, while emit the signalShowMsgbox in another thread:

                  while signal and slot are no in the same thread, isn't AutoConn==QueuedConn??

                  It should be. It does not hurt to make it explicit, though.

                  can i catch this exception(@Qt5Guid.dll), and just ignore it ?

                  Qt does not throw any exceptions, so it is rather something "deeper". You can try if you want, but ignoring a stack overflow seems like a bad idea.

                  Try using heap instead, like you suggested. Example pseudo-code:

                  auto msg = new QMessageBox(this);
                  msg->setTitle(title);
                  msg->setText(text);
                  connect (msg, &QMessageBox::finished, msg, &QMessageBox::deleteLater);
                  msg->exec();
                  

                  (Z(:^

                  1 Reply Last reply
                  3
                  • O Offline
                    O Offline
                    opengpu2
                    wrote on last edited by
                    #9

                    thank you very much!

                    1 Reply Last reply
                    0

                    • Login

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