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. The program crashes suddenly when working with a new feature
Forum Updated to NodeBB v4.3 + New Features

The program crashes suddenly when working with a new feature

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 7 Posters 5.1k Views 2 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.
  • VRoninV VRonin

    Just run using the debugger, crash your program and look at the stack trace window

    tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #8

    @VRonin

    It's more than 20 times I'm testing the program after running it by F5. But extremely astonishing, the program doesn't crash!!!! I changed nothing in the code.

    I should dedicate more time and hopefully see it crash. But, where is the window called "stack trace window", please?

    0_1551787511732_Capture.PNG

    VRoninV 1 Reply Last reply
    0
    • tomyT tomy

      @VRonin

      It's more than 20 times I'm testing the program after running it by F5. But extremely astonishing, the program doesn't crash!!!! I changed nothing in the code.

      I should dedicate more time and hopefully see it crash. But, where is the window called "stack trace window", please?

      0_1551787511732_Capture.PNG

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #9

      @tomy said in The program crashes suddenly when working with a new feature:

      where is the window called "stack trace window", please?

      It's the one in the bottom right corner

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by
        #10

        I ran the program with Debugger (F5) and tested it for crash many a time, but thus far it's never crashed in this mode. But when I run it by crtl+R, it crashes at the second or third time I apply the sum action on the highlighted cells!
        Why please? Does the debugger change the behavior of the program, please?

        Here is the project spreadsheet.rar. Please if possible test it and let me know what makes the program crash, please?
        I wanted to upload it here but faced a message saying I haven't that privilege! so posted that below:
        https://www.dropbox.com/s/anuk091qr8tjeem/spreadsheet.rar?dl=0

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #11

          Hi,

          Check for uninitialised pointers and/or variables. In debug mode, the pointers at least are initialised to zero but not in release mode (that's nothing Qt specific though)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by tomy
            #12

            I changed the initial value of some pointers from 0 to nullptr and also assigned 0 to some uninitialized variables too ( E.g., quint16) then reran the project and tested for the crash. This time I got this message at the time of crash:

            12:53:28: Starting C:\Users\Abbasi\Desktop\Documents\Qt\qt-book\chap03\build-spreadsheet-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\debug\spreadsheet.exe...
            ASSERT: "size == 0 || offset < 0 || size_t(offset) >= sizeof(QArrayData)" in file..\..\include/QtCore/../../src/corelib/tools/qarraydata.h, line 67
            12:53:50: The program has unexpectedly finished.
            12:53:50: The process was ended forcefully.
            12:53:51: C:/Users/Abbasi/Desktop/Documents/Qt/qt-book/chap03/build-spreadsheet-Desktop_Qt_5_12_0_MinGW_64_bit-Debug/debug/spreadsheet.exe crashed.

            And when I clicked on that file I got this message:

            0_1552123884284_Capture.PNG

            By the way, I always run the programs in the Debug mode unless they're in their last state before creating an installer for them. So all crashes have happened in the Debug mode so far.

            And still by the Debugger, I get no crashes!!

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

              You're hitting an assertion because you are accesing a QVector/QList with an index which is out-of-bounds. Take a look at the backtrace to see from where the call is coming.

              So all crashes have happened in the Debug mode so far. And still by the Debugger, I get no crashes!!

              This somehow makes no sense from me - either it crashes in debug or not.

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

              J.HilkJ tomyT 2 Replies Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                You're hitting an assertion because you are accesing a QVector/QList with an index which is out-of-bounds. Take a look at the backtrace to see from where the call is coming.

                So all crashes have happened in the Debug mode so far. And still by the Debugger, I get no crashes!!

                This somehow makes no sense from me - either it crashes in debug or not.

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

                @Christian-Ehrlicher
                as far as i unerstand it, it‘s always a debug build but only crashes, when rhe debugger is not attached.

                which is unusual.

                You could potentially try attaching the debugger after wards to the running process via VS.


                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
                1
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  Since it's an assertion it will also happen when a debugger is attached. And that's also the reason why it does 'work' in release mode.

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

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    You're hitting an assertion because you are accesing a QVector/QList with an index which is out-of-bounds. Take a look at the backtrace to see from where the call is coming.

                    So all crashes have happened in the Debug mode so far. And still by the Debugger, I get no crashes!!

                    This somehow makes no sense from me - either it crashes in debug or not.

                    tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by tomy
                    #16

                    @Christian-Ehrlicher

                    Take a look at the backtrace to see from where the call is coming.

                    As I said, when run by the Debugger, the project never crashes, at least based on my many tests' result!

                    This somehow makes no sense from me - either it crashes in debug or not.

                    I don't use the Release mode, so please let's drop this word down for the time being.

                    I run the program only in the Debug mode, either by pressing F5 (which is the Debugger) or ctrl+R (which is a rormal run).

                    • When run normally: Crash occurs.
                    • when run by the Debugger: Crash doesn't occur.

                    Why don't you simply download and run the project, please?

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @tomy said in The program crashes suddenly when working with a new feature:

                      QTableWidgetItem* item = new QTableWidgetItem;

                      This is wrong, you have to use 'Cell' ...

                      Cell *Spreadsheet::cell(int row, int column) const
                      {
                          return static_cast<Cell *>(item(row, column));
                      }
                      

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

                      tomyT 1 Reply Last reply
                      3
                      • Christian EhrlicherC Christian Ehrlicher

                        @tomy said in The program crashes suddenly when working with a new feature:

                        QTableWidgetItem* item = new QTableWidgetItem;

                        This is wrong, you have to use 'Cell' ...

                        Cell *Spreadsheet::cell(int row, int column) const
                        {
                            return static_cast<Cell *>(item(row, column));
                        }
                        
                        tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on last edited by tomy
                        #18

                        @Christian-Ehrlicher

                        Do you mean I use sum() this way:

                        void Spreadsheet::sum()
                        {
                            double d = 0.0;
                        
                            QList<QTableWidgetItem *> items = selectedItems();
                        
                            if(add(items, d)) {
                                int row = 0, column = 0;
                                position(items, row, column);
                        
                                ++row;
                                Cell *c = cell(row, column);
                                c->setTextAlignment(Qt::AlignRight);
                                c->setText((QString::number(d)));
                        
                                somethingChanged();
                            }
                        }
                        

                        It still crashes.

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #19

                          @tomy said in The program crashes suddenly when working with a new feature:

                          It still crashes.

                          But this time your debugger will show you where...

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

                          tomyT 1 Reply Last reply
                          3
                          • Christian EhrlicherC Christian Ehrlicher

                            @tomy said in The program crashes suddenly when working with a new feature:

                            It still crashes.

                            But this time your debugger will show you where...

                            tomyT Offline
                            tomyT Offline
                            tomy
                            wrote on last edited by
                            #20

                            @Christian-Ehrlicher
                            Right!

                            0_1552139876140_4.PNG ![0_1552139887443_5.PNG]

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #21

                              So when you go up the backtrace you see that "Cell *c = cell(row, column);" returns a nullptr.

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

                              tomyT 1 Reply Last reply
                              2
                              • Christian EhrlicherC Christian Ehrlicher

                                So when you go up the backtrace you see that "Cell *c = cell(row, column);" returns a nullptr.

                                tomyT Offline
                                tomyT Offline
                                tomy
                                wrote on last edited by
                                #22

                                @Christian-Ehrlicher

                                So when you go up the backtrace you see that "Cell *c = cell(row, column);" returns a nullptr.

                                Since it's empty, yeah?

                                So how to get to the next row (which may or may not be empty) to set the result into it, please?

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #23

                                  When there is no object (yet) you should create one, or?

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

                                  tomyT 2 Replies Last reply
                                  0
                                  • Christian EhrlicherC Christian Ehrlicher

                                    When there is no object (yet) you should create one, or?

                                    tomyT Offline
                                    tomyT Offline
                                    tomy
                                    wrote on last edited by tomy
                                    #24

                                    @Christian-Ehrlicher
                                    I was doing it by:

                                    QTableWidgetItem* item = new QTableWidgetItem;

                                    I don't know why we need: Cell *c = cell(row, column); while it's the last filled cell and we can't increase its row number to get to the next cell to put the result of sum() into it!

                                    1 Reply Last reply
                                    0
                                    • Christian EhrlicherC Offline
                                      Christian EhrlicherC Offline
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #25

                                      I already told you that you don't have to use QTableWidgetItem but Cell since the model is working with Cell objects (which derives from QTableWidgetItem) instead QTableWidgetItem and therefore the static cast does undefined stuff -> c++ basics...

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

                                      1 Reply Last reply
                                      3
                                      • Christian EhrlicherC Christian Ehrlicher

                                        When there is no object (yet) you should create one, or?

                                        tomyT Offline
                                        tomyT Offline
                                        tomy
                                        wrote on last edited by tomy
                                        #26

                                        @Christian-Ehrlicher

                                        When there is no object (yet) you should create one, or?

                                        Using this statement: Cell* c = cell(row, column); we can only have c as a pointer to a non-empty cell in the sheet. Moreover, we can't make it point to the next cell as our target cell for putting the result of our function, because the program crashes. So that c is useless.

                                        What do you mean by creating an object? And object of what? A cell? If so, how? This way: Cell ce = *cell(row, column);?

                                        I really don't understand what your intention is.
                                        Isn't there any way to solve this issue?

                                        1 Reply Last reply
                                        0
                                        • Christian EhrlicherC Offline
                                          Christian EhrlicherC Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #27

                                          How to create a new object on the heap: http://www.cplusplus.com/reference/new/operator new/

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

                                          tomyT 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