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.9k 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.
  • C Christian Ehrlicher
    24 Mar 2019, 11:24

    @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.

    E Offline
    E Offline
    Engelard
    wrote on 24 Mar 2019, 12:00 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();

    J 1 Reply Last reply 24 Mar 2019, 12:03
    0
    • E Engelard
      24 Mar 2019, 12:00

      @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();

      J Online
      J Online
      JonB
      wrote on 24 Mar 2019, 12:03 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
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 24 Mar 2019, 12:19 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.

        E 1 Reply Last reply 25 Mar 2019, 06:06
        1
        • E Engelard
          24 Mar 2019, 09:49

          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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 24 Mar 2019, 13:00 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.

          J 1 Reply Last reply 24 Mar 2019, 13:09
          2
          • J J.Hilk
            24 Mar 2019, 13:00

            @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.

            J Online
            J Online
            JonB
            wrote on 24 Mar 2019, 13:09 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 1 Reply Last reply 24 Mar 2019, 16:37
            0
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 24 Mar 2019, 14:37 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

              J 1 Reply Last reply 24 Mar 2019, 18:16
              4
              • J JonB
                24 Mar 2019, 13:09

                @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 Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 24 Mar 2019, 16:37 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
                • C Christian Ehrlicher
                  24 Mar 2019, 14:37

                  @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.

                  J Online
                  J Online
                  JonB
                  wrote on 24 Mar 2019, 18:16 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
                  • M mrjj
                    24 Mar 2019, 12:19

                    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.

                    E Offline
                    E Offline
                    Engelard
                    wrote on 25 Mar 2019, 06:06 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

                    A 1 Reply Last reply 25 Mar 2019, 06:31
                    0
                    • E Engelard
                      25 Mar 2019, 06:06

                      @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

                      A Offline
                      A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on 25 Mar 2019, 06:31 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
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 25 Mar 2019, 07:34 last edited by mrjj
                        #18

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

                        1 Reply Last reply
                        1
                        • E Offline
                          E Offline
                          Engelard
                          wrote on 25 Mar 2019, 08:47 last edited by Engelard
                          #19

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

                          M 1 Reply Last reply 25 Mar 2019, 08:48
                          0
                          • E Engelard
                            25 Mar 2019, 08:47

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

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 25 Mar 2019, 08:48 last edited by
                            #20

                            @Engelard
                            and that is from it crashes ?

                            E 1 Reply Last reply 25 Mar 2019, 08:53
                            0
                            • M mrjj
                              25 Mar 2019, 08:48

                              @Engelard
                              and that is from it crashes ?

                              E Offline
                              E Offline
                              Engelard
                              wrote on 25 Mar 2019, 08:53 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
                              • E Offline
                                E Offline
                                Engelard
                                wrote on 25 Mar 2019, 08:56 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 1 Reply Last reply 25 Mar 2019, 09:11
                                0
                                • H Offline
                                  H Offline
                                  hskoglund
                                  wrote on 25 Mar 2019, 09:06 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()?

                                  E 1 Reply Last reply 25 Mar 2019, 09:12
                                  0
                                  • E Engelard
                                    25 Mar 2019, 08:56

                                    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 Offline
                                    J Offline
                                    J.Hilk
                                    Moderators
                                    wrote on 25 Mar 2019, 09:11 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.

                                    E 1 Reply Last reply 25 Mar 2019, 09:18
                                    3
                                    • H hskoglund
                                      25 Mar 2019, 09:06

                                      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()?

                                      E Offline
                                      E Offline
                                      Engelard
                                      wrote on 25 Mar 2019, 09:12 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 J.Hilk
                                        25 Mar 2019, 09:11

                                        @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(...);
                                        }
                                        
                                        E Offline
                                        E Offline
                                        Engelard
                                        wrote on 25 Mar 2019, 09:18 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
                                        • E Offline
                                          E Offline
                                          Engelard
                                          wrote on 25 Mar 2019, 09:42 last edited by Engelard
                                          #27

                                          Oh, finally! With the help of @J-Hilk i realised what was wrong.

                                          1. add if-cheks in "lights" functions.
                                          2. assign currentButton to nullptr in the constructor. (i mistakenly thought that created pointers of the objects without assignment by default nullptr)

                                          Now no crashes. Tnx @J-Hilk !

                                          1 Reply Last reply
                                          0

                                          17/27

                                          25 Mar 2019, 06:31

                                          • Login

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