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. Some error occuring on destructor
Forum Updated to NodeBB v4.3 + New Features

Some error occuring on destructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 7 Posters 7.1k Views 3 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 Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    Do we know what type of exception or any text from it ?
    I suspect the database is no longer valid, or has open queries.

    O 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Do we know what type of exception or any text from it ?
      I suspect the database is no longer valid, or has open queries.

      O Offline
      O Offline
      Ovidiu_GCO
      wrote on last edited by Ovidiu_GCO
      #3

      @mrjj Thank you for your quick reply!

      Severity	Code	Description	Project	File	Line	Suppression State
      Error (active)	E2512	the argument to a feature-test macro must be a simple identifier	F1_System	C:\Qt\Qt5.11.2\5.11.2\msvc2017_64\include\QtCore\qcompilerdetection.h	1327	
      
      

      This is the error shown in the error list.

      Why would a query still be open? It didn't while I was working with the old code.

      LE: It occurs when I close that window.

      mrjjM 1 Reply Last reply
      0
      • O Ovidiu_GCO

        @mrjj Thank you for your quick reply!

        Severity	Code	Description	Project	File	Line	Suppression State
        Error (active)	E2512	the argument to a feature-test macro must be a simple identifier	F1_System	C:\Qt\Qt5.11.2\5.11.2\msvc2017_64\include\QtCore\qcompilerdetection.h	1327	
        
        

        This is the error shown in the error list.

        Why would a query still be open? It didn't while I was working with the old code.

        LE: It occurs when I close that window.

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

        @Ovidiu_GCO
        Hi
        Ehh that seems completely unrelated to the code, i must say.
        if you //QSqlDatabase::database("dataB").close();
        does it still happen ?

        O 1 Reply Last reply
        0
        • mrjjM mrjj

          @Ovidiu_GCO
          Hi
          Ehh that seems completely unrelated to the code, i must say.
          if you //QSqlDatabase::database("dataB").close();
          does it still happen ?

          O Offline
          O Offline
          Ovidiu_GCO
          wrote on last edited by
          #5

          @mrjj Yup, it still occurs right at the closing bracket of the destructor :(

          mrjjM 1 Reply Last reply
          0
          • O Ovidiu_GCO

            @mrjj Yup, it still occurs right at the closing bracket of the destructor :(

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

            @Ovidiu_GCO
            So its not the code but something else. (it seems)
            Any chance pickParticipants is deleted twice ?
            Also, did you try a complete clean build ?

            Also, did you update VS lately, as it does sound like
            https://forum.qt.io/topic/93711/problem-with-new-visual-studio-update-2017-version-15-8-0-and-qt-5-9-5

            O 1 Reply Last reply
            1
            • mrjjM mrjj

              @Ovidiu_GCO
              So its not the code but something else. (it seems)
              Any chance pickParticipants is deleted twice ?
              Also, did you try a complete clean build ?

              Also, did you update VS lately, as it does sound like
              https://forum.qt.io/topic/93711/problem-with-new-visual-studio-update-2017-version-15-8-0-and-qt-5-9-5

              O Offline
              O Offline
              Ovidiu_GCO
              wrote on last edited by
              #7

              @mrjj pickParticipants deleted twice? I don't call on the destructor anywhere else, if this is what you are asking.

              Nope, didn't update VS since installation.

              I just remembered something, last time it was working fine, I tried to open another window(inside this app, using a button) and it kinda flick a few times(and it didn't open at anytime). Do you think that could cause some memory damage or something like that?

              mrjjM 1 Reply Last reply
              0
              • O Ovidiu_GCO

                @mrjj pickParticipants deleted twice? I don't call on the destructor anywhere else, if this is what you are asking.

                Nope, didn't update VS since installation.

                I just remembered something, last time it was working fine, I tried to open another window(inside this app, using a button) and it kinda flick a few times(and it didn't open at anytime). Do you think that could cause some memory damage or something like that?

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

                @Ovidiu_GCO
                Yes something like manual deletion. But sounds not like it.
                Could you try a fresh project ?
                Im not sure if something in VS got damaged. the error seems very odd.

                1 Reply Last reply
                0
                • O Ovidiu_GCO

                  Hello!

                  I just refactored some code in the constructor and now the destructor seems to have some problems (see the picture).

                  0_1546986910299_error.PNG

                  Any ideas?

                  Here is my code :

                  #include "pickParticipants.h"
                  #include <QtSql/qsqldatabase.h>
                  #include <QtSql/qsqlquery.h>
                  #include <qtablewidget.h>
                  #include <QtCore>
                  
                  pickParticipants::pickParticipants(QWidget *parent)
                  	: QDialog(parent)
                  {
                  	ui.setupUi(this);
                  
                  	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deletePilot()));
                  	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewPilot_Button()));
                  	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(openCircuits()));
                  
                  	if (QSqlDatabase::database("dataB").open()) {
                  		//SQL Query that fetches all the pilots along with their team and car specs
                  		QString selectAllPilots("SELECT Piloti.nume, Piloti.prenume, Echipe.nume, Masini.Serie_Sasiu, Masini.numar_masina, Masini.putere_motor, Masini.capacitate_motor FROM Piloti JOIN Echipe ON Piloti.ID_Echipa = Echipe.ID_Echipa JOIN Masini ON Piloti.ID_Pilot = Masini.ID_Pilot;");
                  		//Execute "selectAllPilots" query against "dataB" database
                  		QSqlQuery qry(selectAllPilots, QSqlDatabase::database("dataB"));
                  
                  		//Count the number of records
                  		int rowCounter = 0;
                  
                  		//Build drivers table
                  		while (qry.next()) {
                  			ui.driversTable->insertRow(rowCounter);
                  			ui.driversTable->setItem(rowCounter, 0, new QTableWidgetItem(qry.value(0).toString() + " " + qry.value(1).toString()));
                  
                  			for (int colCounter = 1; colCounter < ui.driversTable->columnCount(); colCounter++) {
                  				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter + 1).toString()));
                  			}
                  
                  			rowCounter++;
                  		}
                  
                  	}
                  }
                  
                  pickParticipants::~pickParticipants() {
                  
                  	QSqlDatabase::database("dataB").close();
                  }
                  
                  void pickParticipants::addNewPilot_Button() {
                  	//Set up the window
                  	addNewPilot addPilotWindow;
                  	addPilotWindow.setModal(true);
                  	//Show the window
                  	addPilotWindow.show();
                  
                  }
                  
                  void pickParticipants::deletePilot() {
                  
                  }
                  
                  void pickParticipants::openCircuits() {
                  	//moving to the next screen "resultPage"
                  		//hide the "Pick Participants" UI
                  	this->hide();
                  	//set the new page "PickParticipants"
                  	resultPage resultPageUI;
                  	resultPageUI.setModal(true);
                  	//show the new page
                  	resultPageUI.exec();
                  }
                  
                  

                  Thank you!

                  PS: Before refactoring the code it was working without problems

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

                  @Ovidiu_GCO said in Some error occuring on destructor:

                  void pickParticipants::addNewPilot_Button() {
                  //Set up the window
                  addNewPilot addPilotWindow;
                  addPilotWindow.setModal(true);
                  //Show the window
                  addPilotWindow.show();

                  }

                  This is not going to work as addPilotWindow is going out of scope and is deleted when addNewPilot_Button finishes. You should either allocate it on the heap or use exec().
                  Also you should check the stack trace when you get that exception to see what happens at that time.

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

                  O 1 Reply Last reply
                  4
                  • jsulmJ jsulm

                    @Ovidiu_GCO said in Some error occuring on destructor:

                    void pickParticipants::addNewPilot_Button() {
                    //Set up the window
                    addNewPilot addPilotWindow;
                    addPilotWindow.setModal(true);
                    //Show the window
                    addPilotWindow.show();

                    }

                    This is not going to work as addPilotWindow is going out of scope and is deleted when addNewPilot_Button finishes. You should either allocate it on the heap or use exec().
                    Also you should check the stack trace when you get that exception to see what happens at that time.

                    O Offline
                    O Offline
                    Ovidiu_GCO
                    wrote on last edited by Ovidiu_GCO
                    #10

                    @jsulm When would it be deleted exactly? I use it just to insert a new pilot in my database.

                    Could you also explain me a little how could I check the stack trace?

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

                      Hi,

                      When the addNewPilot_Button function ends which is exactly after addPilotWindow.show() is called.

                      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
                      0
                      • O Ovidiu_GCO

                        @jsulm When would it be deleted exactly? I use it just to insert a new pilot in my database.

                        Could you also explain me a little how could I check the stack trace?

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

                        @Ovidiu_GCO Why don't you simply use exec() instead of show()?

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

                        O 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Ovidiu_GCO Why don't you simply use exec() instead of show()?

                          O Offline
                          O Offline
                          Ovidiu_GCO
                          wrote on last edited by
                          #13

                          @jsulm I changed it to .exec(). I don't know why I used .show() this time, all over my code I used .exec(). Thank you!

                          @SGaist I get it now, but I would use that window to insert a pilot's information into the database, so it wouldn't bother me.

                          I didn't manage to clear that error using any of the ideas above, but I still have to check the stack trace if you could tell me how.

                          Thank you!

                          1 Reply Last reply
                          0
                          • O Offline
                            O Offline
                            Ovidiu_GCO
                            wrote on last edited by
                            #14

                            I don't know if this helps, but I got this in the Output Window:

                            Debug Assertion Failed!
                            
                            Program: ...l III\BD\Proiect\Qt_Project\F1_System\x64\Debug\F1_System.exe
                            File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
                            Line: 908
                            
                            Expression: is_block_type_valid(header->_block_use)
                            
                            For information on how your program can cause an assertion
                            failure, see the Visual C++ documentation on asserts.
                            
                            (Press Retry to debug the application)
                            The thread 0x370c has exited with code 0 (0x0).
                            The thread 0x1d74 has exited with code 0 (0x0).
                            The thread 0x36c8 has exited with code 0 (0x0).
                            
                            
                            JonBJ 1 Reply Last reply
                            0
                            • O Ovidiu_GCO

                              I don't know if this helps, but I got this in the Output Window:

                              Debug Assertion Failed!
                              
                              Program: ...l III\BD\Proiect\Qt_Project\F1_System\x64\Debug\F1_System.exe
                              File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
                              Line: 908
                              
                              Expression: is_block_type_valid(header->_block_use)
                              
                              For information on how your program can cause an assertion
                              failure, see the Visual C++ documentation on asserts.
                              
                              (Press Retry to debug the application)
                              The thread 0x370c has exited with code 0 (0x0).
                              The thread 0x1d74 has exited with code 0 (0x0).
                              The thread 0x36c8 has exited with code 0 (0x0).
                              
                              
                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #15

                              @Ovidiu_GCO
                              I don't know what is actually wrong in your code. However the stack trace tells us, not surprisingly, that it has overwritten dynamically allocated memory incorrectly, or possibly is trying to free a block which is not allocated. I presume this could occur on memory allocated/freed via C++ new/delete, as well as C malloc/free etc., though not certain whether the C++ have their own memory allocation catchers. Don't know if you can use this to help track down your problem....

                              O 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @Ovidiu_GCO
                                I don't know what is actually wrong in your code. However the stack trace tells us, not surprisingly, that it has overwritten dynamically allocated memory incorrectly, or possibly is trying to free a block which is not allocated. I presume this could occur on memory allocated/freed via C++ new/delete, as well as C malloc/free etc., though not certain whether the C++ have their own memory allocation catchers. Don't know if you can use this to help track down your problem....

                                O Offline
                                O Offline
                                Ovidiu_GCO
                                wrote on last edited by
                                #16

                                @JonB You are right, something is wrong with memory allocation.

                                I just tried to comment some of my code and it seems that the problem is located inside this while loop:

                                while (qry.next()) {
                                			ui.driversTable->insertRow(rowCounter);
                                			ui.driversTable->setItem(rowCounter, 0, new QTableWidgetItem(qry.value(0).toString() + " " + qry.value(1).toString()));
                                
                                			//we use "ui.driversTable->columnCount() - 1" because the last column is a checkbox
                                			for (int colCounter = 1; colCounter < ui.driversTable->columnCount() - 1 ; colCounter++) {
                                				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter + 1).toString()));
                                			}
                                
                                			rowCounter++;
                                		}
                                

                                I suspect the setItem() lines, but I read in the documentation that the QTableWidget takes ownership of these items, so it shouldn't be a problem.

                                Thank you all for your help and time!

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

                                  Unrelated to the problem at hand but why not use a QTableView / QSqlTableModel or QSqlQueryModel combo ?

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

                                  O 1 Reply Last reply
                                  1
                                  • SGaistS SGaist

                                    Unrelated to the problem at hand but why not use a QTableView / QSqlTableModel or QSqlQueryModel combo ?

                                    O Offline
                                    O Offline
                                    Ovidiu_GCO
                                    wrote on last edited by
                                    #18

                                    @SGaist Because, honestly, I do not know how to use Models/Views

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

                                      Well... You are already using Qt's Model/View since you are using a QTableWidget.

                                      From the QSqlQueryModel documentation:

                                          QSqlQueryModel *model = new QSqlQueryModel;
                                          model->setQuery("SELECT name, salary FROM employee");
                                          model->setHeaderData(0, Qt::Horizontal, tr("Name"));
                                          model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
                                      
                                          QTableView *view = new QTableView;
                                          view->setModel(model);
                                          view->show();
                                      

                                      Adapt that to the query you are using and you should be good to go.

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

                                      O 1 Reply Last reply
                                      3
                                      • SGaistS SGaist

                                        Well... You are already using Qt's Model/View since you are using a QTableWidget.

                                        From the QSqlQueryModel documentation:

                                            QSqlQueryModel *model = new QSqlQueryModel;
                                            model->setQuery("SELECT name, salary FROM employee");
                                            model->setHeaderData(0, Qt::Horizontal, tr("Name"));
                                            model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
                                        
                                            QTableView *view = new QTableView;
                                            view->setModel(model);
                                            view->show();
                                        

                                        Adapt that to the query you are using and you should be good to go.

                                        O Offline
                                        O Offline
                                        Ovidiu_GCO
                                        wrote on last edited by
                                        #20

                                        @SGaist I will try it as a workaround, but I am still curious about that error.

                                        Thank you!

                                        1 Reply Last reply
                                        0
                                        • O Ovidiu_GCO

                                          @JonB You are right, something is wrong with memory allocation.

                                          I just tried to comment some of my code and it seems that the problem is located inside this while loop:

                                          while (qry.next()) {
                                          			ui.driversTable->insertRow(rowCounter);
                                          			ui.driversTable->setItem(rowCounter, 0, new QTableWidgetItem(qry.value(0).toString() + " " + qry.value(1).toString()));
                                          
                                          			//we use "ui.driversTable->columnCount() - 1" because the last column is a checkbox
                                          			for (int colCounter = 1; colCounter < ui.driversTable->columnCount() - 1 ; colCounter++) {
                                          				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter + 1).toString()));
                                          			}
                                          
                                          			rowCounter++;
                                          		}
                                          

                                          I suspect the setItem() lines, but I read in the documentation that the QTableWidget takes ownership of these items, so it shouldn't be a problem.

                                          Thank you all for your help and time!

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

                                          @Ovidiu_GCO
                                          I do not see anything obvious in the code you show or comment out which would lead to the error. Remember that when dealing with memory allocation issues, the route the code happens to follow can show up or hide a problem, so a change unrelated to a problem can cause it to occur or disappear.

                                          When you hit the assertion failure while running in the debugger, it should stop. There is a window with a "stack trace" of all the function calls leading to the assert. You should show us that output, it may contain function names which give a clue. This is a vital window in debugging, you want to find it.

                                          Also since the assert is on destruction of pickParticipants object as a whole, you might also show us the calling code, where you create & destroy the instance?

                                          Are you quite sure that everything has been rebuilt from clean, as @mrjj suggested?

                                          O 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