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. My program start to crash because of MessageBox
Forum Updated to NodeBB v4.3 + New Features

My program start to crash because of MessageBox

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 7 Posters 6.1k 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.
  • EngelardE Engelard

    @JonB said in My program start to crash because of MessageBox:

    That is wrong. Create a standalone program which does nothing other than display this message box and test.

    I told already that it worked like half day ago, now it's crashed, exactly when i call this function, i did nothing global or related to this function in my program.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #7

    @Engelard
    Then how can anybody possibly know what you might have done to make something which should be able to display some text without problem now not be able to display it, before we ever get as far as crashing?

    Either use a debugger, or chop out the code you added till it works again/build up from a standalone which does work. If you think anyone here is going to be able to tell you why your unknown code "suddenly" does not work, they will not.

    1 Reply Last reply
    1
    • Christian EhrlicherC Christian Ehrlicher

      @Engelard said in My program start to crash because of MessageBox:

      i did nothing global or related to this function in my program.

      But something has changed - and since Qt don't crash just because of a simple QMessageBox call and you're unable to provide a proper testcase or backtrace you're on your own tracking down the problem by e.g. removing stuff until the crash never occurs.

      EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by Engelard
      #8

      @Christian-Ehrlicher said in My program start to crash because of MessageBox:

      and you're unable to provide a proper testcase or backtrace you're on your own tracking down the problem

      Exactly, i can't backtrace it because there is nothing to trace rly, just a small function...

      @JonB said in My program start to crash because of MessageBox:

      Then how can anybody possibly know what you might have done to make something

      Well, maybe it is some another kind of Qt bug, which someone might know how to fix.

      It is not about my function, it is about message box itself, i get same crashes if try use simple static functions like QMessageBox::information();

      JonBJ 1 Reply Last reply
      0
      • EngelardE Engelard

        @Christian-Ehrlicher said in My program start to crash because of MessageBox:

        and you're unable to provide a proper testcase or backtrace you're on your own tracking down the problem

        Exactly, i can't backtrace it because there is nothing to trace rly, just a small function...

        @JonB said in My program start to crash because of MessageBox:

        Then how can anybody possibly know what you might have done to make something

        Well, maybe it is some another kind of Qt bug, which someone might know how to fix.

        It is not about my function, it is about message box itself, i get same crashes if try use simple static functions like QMessageBox::information();

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #9

        @Engelard

        Exactly, i can't backtrace it because there is nothing to trace rly, just a small function...

        Yes, you can, and should. Run the program under the Qt Creator debugger. Assuming it really does "crash", at that point the debugger should catch it. Go to the "stack trace" (or "back trace") window at that point, and paste here whatever information it does have.

        BTW, you can probably also try

        QMessageBox::information(nullptr, "ERROR", text);
        

        and see whether that too "crashes" or not.

        1 Reply Last reply
        4
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #10

          Hi
          Just start the app in debug mode. And then make it crash.
          It should show in call stack what it was doing before it died.

          Also, just for test add a new button and call
          err("TEST");
          to see if that triggers the crash.
          If not, it must have something to do with the surrounding code from where you
          use err() . maybe a dangling pointer.

          EngelardE 1 Reply Last reply
          1
          • EngelardE Engelard

            Hi everyone! Today i added function:

            void MainWindow::err(QString text)
            {
                QMessageBox::information(this, "ERROR", text);
            }
            

            It worked well, but in some point, my program start to crash when i try to use it, and i don't know what changed it and no info about reason of crash from Qt...

            Please help, i need such error handler back!

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #11

            @Engelard what os and qt version is this?

            I had some issues like this under ios and 5.12.0 went away with one of the later updates

            also do you call processEvents() somewhre inside your code?
            the static call to QMessageBox spins its own QEventLoop. That on combination with processEvent calls can cause very strange behaviour and crashes.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            JonBJ 1 Reply Last reply
            2
            • J.HilkJ J.Hilk

              @Engelard what os and qt version is this?

              I had some issues like this under ios and 5.12.0 went away with one of the later updates

              also do you call processEvents() somewhre inside your code?
              the static call to QMessageBox spins its own QEventLoop. That on combination with processEvent calls can cause very strange behaviour and crashes.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #12

              @J.Hilk

              QMessageBox::information();
              

              just as that statement, blocks, spins its own loop, and does not return till the user has pressed a button, correct or not? So you can't be calling processEvents() elsewhere in your own code, unless you're doing something really odd, is that not right?

              J.HilkJ 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @JonB said in My program start to crash because of MessageBox:

                is that not right

                When there is a timer which is executed while the message box is shown and in the slot you call processEvents() you will get likely into trouble.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                JonBJ 1 Reply Last reply
                4
                • JonBJ JonB

                  @J.Hilk

                  QMessageBox::information();
                  

                  just as that statement, blocks, spins its own loop, and does not return till the user has pressed a button, correct or not? So you can't be calling processEvents() elsewhere in your own code, unless you're doing something really odd, is that not right?

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #14

                  @JonB Just because you call start on an other event loop doesn't mean your original one simply stops.

                  You get a general setDisbaled on your MainApplication Ui, everything else is still going on normally.

                  Take this example, based on what @Christian-Ehrlicher said:

                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                  
                      QTimer alive;
                      QObject::connect(&alive, &QTimer::timeout, []()->void{qDebug("Alive");});
                      alive.start(500);
                  
                      QPushButton btn;
                      btn.show();
                      QObject::connect(&btn, &QPushButton::clicked, []()->void{
                                           QMessageBox::information(nullptr, QString("Error"), QString("Some Error Text"));
                                       });
                  
                      return a.exec();
                  }
                  

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  3
                  • Christian EhrlicherC Christian Ehrlicher

                    @JonB said in My program start to crash because of MessageBox:

                    is that not right

                    When there is a timer which is executed while the message box is shown and in the slot you call processEvents() you will get likely into trouble.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #15

                    @Christian-Ehrlicher , @J-Hilk
                    Yep, fair enough, thank you. I was not thinking about a timer. And nor about a timer calling processEvents(), which I would think would not be advisable!

                    We shall see whether the OP's problem stems from this.

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Hi
                      Just start the app in debug mode. And then make it crash.
                      It should show in call stack what it was doing before it died.

                      Also, just for test add a new button and call
                      err("TEST");
                      to see if that triggers the crash.
                      If not, it must have something to do with the surrounding code from where you
                      use err() . maybe a dangling pointer.

                      EngelardE Offline
                      EngelardE Offline
                      Engelard
                      wrote on last edited by Engelard
                      #16

                      @mrjj said in My program start to crash because of MessageBox:

                      Just start the app in debug mode. And then make it crash.
                      It should show in call stack what it was doing before it died.

                      It shows numerous windows like this:

                      0_1553493942688_1111.jpg

                      What is all mean?

                      0_1553493971315_mmm.jpg

                      @J.Hilk said in My program start to crash because of MessageBox:

                      also do you call processEvents() somewhre inside your code?

                      No

                      aha_1980A 1 Reply Last reply
                      0
                      • EngelardE Engelard

                        @mrjj said in My program start to crash because of MessageBox:

                        Just start the app in debug mode. And then make it crash.
                        It should show in call stack what it was doing before it died.

                        It shows numerous windows like this:

                        0_1553493942688_1111.jpg

                        What is all mean?

                        0_1553493971315_mmm.jpg

                        @J.Hilk said in My program start to crash because of MessageBox:

                        also do you call processEvents() somewhre inside your code?

                        No

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        @Engelard said in My program start to crash because of MessageBox:

                        It shows numerous windows like this:

                        These are uninteresting.

                        We need the call stack (also called stack trace, or backtrace)

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        1
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #18

                          Hi
                          the call stack / trace it looks like this
                          alt text

                          1 Reply Last reply
                          1
                          • EngelardE Offline
                            EngelardE Offline
                            Engelard
                            wrote on last edited by Engelard
                            #19

                            0_1553503901234_111.jpg
                            0_1553503907073_222.jpg
                            0_1553503911733_333.jpg

                            mrjjM 1 Reply Last reply
                            0
                            • EngelardE Engelard

                              0_1553503901234_111.jpg
                              0_1553503907073_222.jpg
                              0_1553503911733_333.jpg

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #20

                              @Engelard
                              and that is from it crashes ?

                              EngelardE 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Engelard
                                and that is from it crashes ?

                                EngelardE Offline
                                EngelardE Offline
                                Engelard
                                wrote on last edited by Engelard
                                #21

                                @mrjj If i comment out my line

                                QMessageBox::information(nullptr, "ERROR", "trtrtr");
                                

                                Debugger will be absolutely empty. When i use this static function of messBox, it give me such output.

                                1 Reply Last reply
                                0
                                • EngelardE Offline
                                  EngelardE Offline
                                  Engelard
                                  wrote on last edited by Engelard
                                  #22

                                  Hey i just found that it work well if i put it in the constructor, so it crashes only when it in my other functions, strange.

                                  UPDATE:

                                  Here is info for everyone. Yesterday, i noticed that the app not just crashed, it crashed like.. twice, and all my app mostly about the use of "pressed" and "released" SLOTs of the buttons. I removed usage of release slot, and now app do just single crash. Here is how "release button" chain looks like:

                                  void MainWindow::on_button_Q_released()
                                  {
                                      //lightRestore(currentButton);
                                  }
                                  

                                  And here is that only function which it use:

                                  void MainWindow::lightRestore(QPushButton *lamp)
                                  {
                                      lamp->setStyleSheet("QPushButton{color: white;background-color: rgb(35,35,35);border-style: outset;border-width: 2px;border-radius: 15px;border-color:  black;font: bold 12px;}");
                                  }
                                  
                                  J.HilkJ 1 Reply Last reply
                                  0
                                  • hskoglundH Offline
                                    hskoglundH Offline
                                    hskoglund
                                    wrote on last edited by
                                    #23

                                    Hi, if I read the trace correctly, the user presses the button_G, that functions calls mainJourney() which issues the QMessageBox() call.
                                    Could you show the code for mainJourney()?

                                    EngelardE 1 Reply Last reply
                                    0
                                    • EngelardE Engelard

                                      Hey i just found that it work well if i put it in the constructor, so it crashes only when it in my other functions, strange.

                                      UPDATE:

                                      Here is info for everyone. Yesterday, i noticed that the app not just crashed, it crashed like.. twice, and all my app mostly about the use of "pressed" and "released" SLOTs of the buttons. I removed usage of release slot, and now app do just single crash. Here is how "release button" chain looks like:

                                      void MainWindow::on_button_Q_released()
                                      {
                                          //lightRestore(currentButton);
                                      }
                                      

                                      And here is that only function which it use:

                                      void MainWindow::lightRestore(QPushButton *lamp)
                                      {
                                          lamp->setStyleSheet("QPushButton{color: white;background-color: rgb(35,35,35);border-style: outset;border-width: 2px;border-radius: 15px;border-color:  black;font: bold 12px;}");
                                      }
                                      
                                      J.HilkJ Online
                                      J.HilkJ Online
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by
                                      #24

                                      @Engelard said in My program start to crash because of MessageBox:

                                      currentButton

                                      seems like currentButton is no longer a valid QPushButton-Pointer,

                                      If you have a pointer member variable, you should make sure that you always set it to a nullptr when the pointed to object is destroyed/invalid.
                                      And always check against that before accessing it:

                                      void MainWindow::lightRestore(QPushButton *lamp)
                                      {
                                          if(lamp)
                                              lamp->setStyleSheet(...);
                                      }
                                      

                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      EngelardE 1 Reply Last reply
                                      3
                                      • hskoglundH hskoglund

                                        Hi, if I read the trace correctly, the user presses the button_G, that functions calls mainJourney() which issues the QMessageBox() call.
                                        Could you show the code for mainJourney()?

                                        EngelardE Offline
                                        EngelardE Offline
                                        Engelard
                                        wrote on last edited by Engelard
                                        #25

                                        @hskoglund said in My program start to crash because of MessageBox:

                                        Could you show the code for mainJourney()?

                                        No, that stuff is too big, it called from pressButton SLOT, above much simplier and compact example of release, it does the same crash.

                                        1 Reply Last reply
                                        0
                                        • J.HilkJ J.Hilk

                                          @Engelard said in My program start to crash because of MessageBox:

                                          currentButton

                                          seems like currentButton is no longer a valid QPushButton-Pointer,

                                          If you have a pointer member variable, you should make sure that you always set it to a nullptr when the pointed to object is destroyed/invalid.
                                          And always check against that before accessing it:

                                          void MainWindow::lightRestore(QPushButton *lamp)
                                          {
                                              if(lamp)
                                                  lamp->setStyleSheet(...);
                                          }
                                          
                                          EngelardE Offline
                                          EngelardE Offline
                                          Engelard
                                          wrote on last edited by Engelard
                                          #26

                                          @J.Hilk nice advice, tnx. But it valid(without that messageBox stuff everything works perfectly), i added if-check line. Nothing it changed(2nd crash exist).

                                          UPDATE:

                                          If i put messageBox AFTER assignment of that button - will be no crashes, but also it is not possible to hold the button(because this messageBox take over priority and it is now main waindow).

                                          void MainWindow::on_button_Q_pressed()
                                          {
                                              currentButton = mainJourney('Q');
                                              lightSet(currentButton);
                                              QMessageBox::information(nullptr, "ERROR", "trtrtr");
                                          }
                                          
                                          1 Reply Last reply
                                          1

                                          • Login

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