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.5k 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.
  • 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 Offline
                    J.HilkJ Offline
                    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
                        • EngelardE Offline
                          EngelardE Offline
                          Engelard
                          wrote on 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

                          • Login

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