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.
  • 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
    • JonBJ JonB

      @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 Offline
      O Offline
      Ovidiu_GCO
      wrote on last edited by Ovidiu_GCO
      #22

      @JonB I am trying to use the View/Model approach now so I cannot post the stack trace yet, but I will if this approach won't work.

      Here is the call:

      //moving to the next screen "PickParticipants"
      		//hide the "Add a new tournament" UI
      		this->hide();
      		//set the new page "PickParticipants"
      		pickParticipants pickParticipantsUI;
      		pickParticipantsUI.setModal(true);
      		//show the new page
      		pickParticipantsUI.exec();
      

      But there is no destruction on that UI...

      And yes, I made a new project and copy-pasted the source code.

      @SGaist I tried to use the code you posted, but it won't show the selection. There is no record in the table. Should I do something else?

      Also, I think this approach won't work for me, because I need to put a checkbox on each table-row. Is this possible?

      JonBJ 1 Reply Last reply
      0
      • O Ovidiu_GCO

        @JonB I am trying to use the View/Model approach now so I cannot post the stack trace yet, but I will if this approach won't work.

        Here is the call:

        //moving to the next screen "PickParticipants"
        		//hide the "Add a new tournament" UI
        		this->hide();
        		//set the new page "PickParticipants"
        		pickParticipants pickParticipantsUI;
        		pickParticipantsUI.setModal(true);
        		//show the new page
        		pickParticipantsUI.exec();
        

        But there is no destruction on that UI...

        And yes, I made a new project and copy-pasted the source code.

        @SGaist I tried to use the code you posted, but it won't show the selection. There is no record in the table. Should I do something else?

        Also, I think this approach won't work for me, because I need to put a checkbox on each table-row. Is this possible?

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

        @Ovidiu_GCO

        But there is no destruction on that UI...

        Conceptually, you need to understand that when you declare a local/stack variable, like your pickParticipants pickParticipantsUI;, then just as there is an implicit construction even though you have no explicit new, so equally there is an implicit destruction when the local variable goes out of scope even though you have no explicit delete. I'm not sure whether you are aware of that.

        The most important thing you have not shown is the stack trace when the assertion occurs.

        1 Reply Last reply
        4
        • O Offline
          O Offline
          Ovidiu_GCO
          wrote on last edited by
          #24

          Sorry for the "long-time-no-answer", I've been really busy with other school projects, but I managed to work a little bit on the file.

          I still have some heap corruption in it, but now it is occurring some other place.

          pickParticipants.cpp:

          #include "pickParticipants.h"
          #include <qtablewidget.h>
          #include <QtCore>
          #include <QtSql/qsqldatabase.h>
          #include <QtSql/qsqlquery.h>
          #include <QtSql/qsqlquerymodel.h>
          #include <qvector.h>
          #include <qstringlist.h>
          
          pickParticipants::pickParticipants(QWidget *parent)
          	: QDialog(parent)
          {
          	ui.setupUi(this);
          
          	//Connect listeners
          	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deletePilot()));
          	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewPilot_Button()));
          	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(updateTableStructure()));
          	
          	//Populate the table
          	this->populatePilotsTable();
          }
          
          pickParticipants::~pickParticipants() {
          
          	QSqlDatabase::database("dataB").close();
          
          }
          
          void pickParticipants::populatePilotsTable() {
          	//Cleaning the table
          	ui.driversTable->setRowCount(0);
          
          	//Open the database and fetch table entries
          	if (QSqlDatabase::database("dataB").open()) {
          		//SQL Query that fetches all the pilots along with their team and car specs
          		QString selectAllPilots("SELECT Piloti.nume, Echipe.nume, Masini.Serie_Sasiu, Masini.numar_masina, Masini.capacitate_motor, Masini.putere_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"));
          
          		//Table row counter
          		int rowCounter = 0;
          
          		//Build drivers table
          		while (qry.next()) {
          			ui.driversTable->insertRow(rowCounter);
          
          			//we use "ui.driversTable->columnCount() - 1" because last column is a checkbox
          			for (int colCounter = 0; colCounter < ui.driversTable->columnCount() - 1; colCounter++) {
          				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter).toString()));
          			}
          
          			//TO-DO insert the checkbox in the last column
          			QTableWidgetItem *checkBoxItem = new QTableWidgetItem();
          			checkBoxItem->setCheckState(Qt::Unchecked);
          			ui.driversTable->setItem(rowCounter, ui.driversTable->columnCount() - 1, checkBoxItem);
          
          			//move to the next row
          			rowCounter++;
          		}
          
          		qry.finish();
          		qry.~QSqlQuery();
          
          	}
          }
          
          void pickParticipants::addNewPilot_Button() {
          	//Set up the window
          	addNewPilot addPilotWindow;
          	addPilotWindow.setModal(true);
          	//Show the window
          	addPilotWindow.exec();
          }
          
          void pickParticipants::deletePilot() {
          									  
          	int selectedRow;
          
          	for (QTableWidgetItem* selectedItem : ui.driversTable->selectedItems()) {
          		if ((*selectedItem).isSelected()) {
          			selectedRow = (*selectedItem).row();
          			break;
          		}
          	}
          
          	//Delete car from database using selected row 
          	QString deleteCar("DELETE FROM Masini WHERE Serie_sasiu = '" + (ui.driversTable->item(selectedRow, 2))->text() + "';");
          	QSqlQuery deleteFromCar(deleteCar, QSqlDatabase::database("dataB"));
          	deleteFromCar.finish();
          
          	//Delete pilot from database using selected row 
          	QString deletePilot("DELETE FROM Piloti WHERE nume = '" + (ui.driversTable->item(selectedRow, 0))->text().split(' ').value(0) + "' AND prenume = '" + (ui.driversTable->item(selectedRow, 0))->text().split(' ').value(1) + "';");
          	QSqlQuery deleteFromPilots(deletePilot, QSqlDatabase::database("dataB"));
          	deleteFromPilots.finish();
          	
          }
          
          //Function to update table's structure
          void pickParticipants::updateTableStructure() {
          	
          	//Saving drivers' IDs before clearing the table
          	this->saveDrivers();
          	//Clearing view, including headers and selections
          	ui.driversTable->clear();
          
          	//Setting up the new structure
          	this->setRaceTableStructure();
          
          	//Setting the number of labels
          	ui.driversTable->setColumnCount(4);
          	//Inserting the labels
          	ui.driversTable->setHorizontalHeaderLabels(labelList);
          
          	//Connecting the listeners to race-related functions
          	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deleteRace()));
          	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewRaceFcn()));
          	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(openResults()));
          
          	labelList.~QStringList();
          	//Populating the table with races
          	this->populateRacesTable();
          
          }
          
          											// Races part
          
          void pickParticipants::addNewRaceFcn() {
          	//Set up the window
          	addNewRace addRaceWindow;
          	addRaceWindow.setModal(true);
          	//Show the window
          	addRaceWindow.exec();
          }
          
          void pickParticipants::deleteRace() {
          
          	int selectedRow;
          
          	for (QTableWidgetItem* selectedItem : ui.driversTable->selectedItems()) {
          		if ((*selectedItem).isSelected()) {
          			selectedRow = (*selectedItem).row();
          			break;
          		}
          	}
          
          	//Delete car from database using selected row 
          	QString deleteRace("DELETE FROM Curse WHERE locatie = '" + (ui.driversTable->item(selectedRow, 0))->text() + "' AND lungime = " + (ui.driversTable->item(selectedRow, 0))->text() + ";");
          	QSqlQuery deleteFromRaces(deleteRace, QSqlDatabase::database("dataB"));
          	deleteFromRaces.finish();
          }
          
          void pickParticipants::openResults() {
          	
          	this->saveRaces();
          
          	//moving to the next screen "resultPage"
          		//hide the "Pick Races" UI
          	this->hide();
          	//set the new page "PickParticipants"
          	resultPage resultPageUI;
          	resultPageUI.setModal(true);
          	//show the new page
          	resultPageUI.exec();
          }
          
          
          void pickParticipants::populateRacesTable() {
          	//Cleaning the table
          	ui.driversTable->setRowCount(0);
          
          	//Open the database and fetch table entries
          	if (QSqlDatabase::database("dataB").open()) {
          		//SQL Query that fetches all the pilots along with their team and car specs
          		QString selectAllRaces("SELECT locatie, numar_ture, lungime FROM Curse;");
          		//Execute "selectAllPilots" query against "dataB" database
          		QSqlQuery qry(selectAllRaces, QSqlDatabase::database("dataB"));
          
          		//Count the number of records
          		int rowCounter = 0;
          
          		qry.first();
          		//Build drivers table
          		while (qry.next()) {
          			ui.driversTable->insertRow(rowCounter);
          
          			//we use "ui.driversTable->columnCount() - 1" because last column is a checkbox
          			for (int colCounter = 0; colCounter < ui.driversTable->columnCount() - 1; colCounter++) {
          				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter).toString()));
          			}
          
          			//TO-DO insert the checkbox in the last column
          			QTableWidgetItem* checkboxItem = new QTableWidgetItem();
          			checkboxItem->setCheckState(Qt::Unchecked);
          			ui.driversTable->setItem(rowCounter, ui.driversTable->columnCount() - 1, checkboxItem);
          			//move to the next row
          			rowCounter++;
          		}
          
          		qry.finish();
          	}
          }
          
          
          //Function to save selected drivers' IDs in vector
          void pickParticipants::saveDrivers() {
          
          	//Query to fetch driver's Id using name
          	QString selectDriverIdByName("SELECT ID_Pilot FROM Piloti WHERE nume = '");
          	for (int rowIterator = 0; rowIterator < ui.driversTable->rowCount(); rowIterator++) {
          		if (ui.driversTable->item(rowIterator, ui.driversTable->columnCount() - 1)->checkState()) { //Pick every driver with checkbox's checkState == 'Checked'(2)
          			//Fetching driver's name from the table
          			QString driverName = ui.driversTable->item(rowIterator, 0)->text() + "';";
          			//Fetching ID from the database and appending it in the drivers' vector
          			QSqlQuery qry(selectDriverIdByName + driverName, QSqlDatabase::database("dataB"));
          			qry.first();
          			driversIdVector.append(qry.value(0).toInt());
          			
          			qry.~QSqlQuery();
          		}
          	}
          }
          
          //Function to save selected races' IDs in vector
          void pickParticipants::saveRaces() {
          
          	//Query to fetch driver's Id using name
          	QString selectRaceIdByLocation("SELECT ID_Cursa FROM Curse WHERE locatie = '");
          	for (int rowIterator = 0; rowIterator < ui.driversTable->rowCount(); rowIterator++) {
          		if (ui.driversTable->item(rowIterator, ui.driversTable->columnCount() - 1)->checkState() == 2) { //Pick every race with checkbox's checkState == 'Checked'(2)
          			//Fetching race's location from the table
          			QString raceLocation = ui.driversTable->item(rowIterator, 0)->text() + "';";
          			//Fetching ID from the database and appending it in the race' vector
          			QSqlQuery qry(selectRaceIdByLocation + raceLocation, QSqlDatabase::database("dataB"));
          			qry.first();
          			racesIdVector.append(qry.value(0).toInt());
          
          			raceLocation.~QString();
          		}
          	}
          }
          
          void pickParticipants::setRaceTableStructure() {
          	
          	//Label list for the Races Table 
          	QStringList labelList = { "Location", "Laps", "Length", "To Tournament" };
          	
          	//Setting the number of labels
          	ui.driversTable->setColumnCount(4);
          	//Inserting the labels
          	ui.driversTable->setHorizontalHeaderLabels(labelList);
          
          	//Connecting the listeners to race-related functions
          	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deleteRace()));
          	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewRaceFcn()));
          	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(openResults()));
          
          	labelList.~QStringList();
          
          }
          

          The error is shown on this->setRaceTableStructure(); inside the void pickParticipants::updateTableStructure() method.

          Call stack:

           	ntdll.dll!RtlpBreakPointHeap()	Unknown
           	ntdll.dll!RtlpValidateHeapEntry()	Unknown
           	ntdll.dll!RtlValidateHeap()	Unknown
           	KernelBase.dll!HeapValidate()	Unknown
           	ucrtbased.dll!_CrtIsValidHeapPointer(const void * block) Line 1407	C++
           	ucrtbased.dll!free_dbg_nolock(void * const block, const int block_use) Line 904	C++
           	ucrtbased.dll!_free_dbg(void * block, int block_use) Line 1030	C++
           	ucrtbased.dll!free(void * block) Line 32	C++
           	Qt5Cored.dll!00007ff899c90265()	Unknown
           	Qt5Cored.dll!00007ff899bf612e()	Unknown
           	Qt5Cored.dll!00007ff899bedac4()	Unknown
           	Qt5Cored.dll!00007ff899c511e7()	Unknown
           	Qt5Cored.dll!00007ff89a0c4e7a()	Unknown
           	Qt5Cored.dll!00007ff89a0cfcba()	Unknown
           	Qt5Cored.dll!00007ff89a0b8910()	Unknown
           	Qt5Cored.dll!00007ff89a0bfffc()	Unknown
           	Qt5Cored.dll!00007ff89a0aaf5e()	Unknown
           	Qt5Cored.dll!00007ff89a0a57f3()	Unknown
           	Qt5Widgetsd.dll!00007ff89b31171b()	Unknown
           	Qt5Widgetsd.dll!00007ff89b312527()	Unknown
           	Qt5Widgetsd.dll!00007ff89b31396a()	Unknown
           	Qt5Widgetsd.dll!00007ff89b314370()	Unknown
           	Qt5Widgetsd.dll!00007ff89b31168f()	Unknown
           	Qt5Widgetsd.dll!00007ff89b331686()	Unknown
           	F1_System.exe!QTableWidgetItem::`scalar deleting destructor'(unsigned int)	C++
           	Qt5Widgetsd.dll!00007ff89b339915()	Unknown
           	Qt5Widgetsd.dll!00007ff89b339837()	Unknown
           	Qt5Widgetsd.dll!00007ff89b334e29()	Unknown
          >	F1_System.exe!pickParticipants::updateTableStructure() Line 109	C++
           	F1_System.exe!pickParticipants::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 90	C++
           	[External Code]	
           	F1_System.exe!addNewTournament::openPilotsTeamsCars() Line 35	C++
           	F1_System.exe!addNewTournament::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 77	C++
           	[External Code]	
           	F1_System.exe!welcomePage::openAddNewTournamentWindow() Line 24	C++
           	F1_System.exe!welcomePage::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 78	C++
           	[External Code]	
           	F1_System.exe!F1_System::validateLogin() Line 40	C++
           	F1_System.exe!F1_System::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 76	C++
           	[External Code]	
           	F1_System.exe!main(int argc, char * * argv) Line 9	C++
           	F1_System.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 104	C++
           	[External Code]	
          
          

          Please, I really need some help on this...

          Thank you for your time!

          jsulmJ 1 Reply Last reply
          0
          • O Ovidiu_GCO

            Sorry for the "long-time-no-answer", I've been really busy with other school projects, but I managed to work a little bit on the file.

            I still have some heap corruption in it, but now it is occurring some other place.

            pickParticipants.cpp:

            #include "pickParticipants.h"
            #include <qtablewidget.h>
            #include <QtCore>
            #include <QtSql/qsqldatabase.h>
            #include <QtSql/qsqlquery.h>
            #include <QtSql/qsqlquerymodel.h>
            #include <qvector.h>
            #include <qstringlist.h>
            
            pickParticipants::pickParticipants(QWidget *parent)
            	: QDialog(parent)
            {
            	ui.setupUi(this);
            
            	//Connect listeners
            	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deletePilot()));
            	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewPilot_Button()));
            	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(updateTableStructure()));
            	
            	//Populate the table
            	this->populatePilotsTable();
            }
            
            pickParticipants::~pickParticipants() {
            
            	QSqlDatabase::database("dataB").close();
            
            }
            
            void pickParticipants::populatePilotsTable() {
            	//Cleaning the table
            	ui.driversTable->setRowCount(0);
            
            	//Open the database and fetch table entries
            	if (QSqlDatabase::database("dataB").open()) {
            		//SQL Query that fetches all the pilots along with their team and car specs
            		QString selectAllPilots("SELECT Piloti.nume, Echipe.nume, Masini.Serie_Sasiu, Masini.numar_masina, Masini.capacitate_motor, Masini.putere_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"));
            
            		//Table row counter
            		int rowCounter = 0;
            
            		//Build drivers table
            		while (qry.next()) {
            			ui.driversTable->insertRow(rowCounter);
            
            			//we use "ui.driversTable->columnCount() - 1" because last column is a checkbox
            			for (int colCounter = 0; colCounter < ui.driversTable->columnCount() - 1; colCounter++) {
            				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter).toString()));
            			}
            
            			//TO-DO insert the checkbox in the last column
            			QTableWidgetItem *checkBoxItem = new QTableWidgetItem();
            			checkBoxItem->setCheckState(Qt::Unchecked);
            			ui.driversTable->setItem(rowCounter, ui.driversTable->columnCount() - 1, checkBoxItem);
            
            			//move to the next row
            			rowCounter++;
            		}
            
            		qry.finish();
            		qry.~QSqlQuery();
            
            	}
            }
            
            void pickParticipants::addNewPilot_Button() {
            	//Set up the window
            	addNewPilot addPilotWindow;
            	addPilotWindow.setModal(true);
            	//Show the window
            	addPilotWindow.exec();
            }
            
            void pickParticipants::deletePilot() {
            									  
            	int selectedRow;
            
            	for (QTableWidgetItem* selectedItem : ui.driversTable->selectedItems()) {
            		if ((*selectedItem).isSelected()) {
            			selectedRow = (*selectedItem).row();
            			break;
            		}
            	}
            
            	//Delete car from database using selected row 
            	QString deleteCar("DELETE FROM Masini WHERE Serie_sasiu = '" + (ui.driversTable->item(selectedRow, 2))->text() + "';");
            	QSqlQuery deleteFromCar(deleteCar, QSqlDatabase::database("dataB"));
            	deleteFromCar.finish();
            
            	//Delete pilot from database using selected row 
            	QString deletePilot("DELETE FROM Piloti WHERE nume = '" + (ui.driversTable->item(selectedRow, 0))->text().split(' ').value(0) + "' AND prenume = '" + (ui.driversTable->item(selectedRow, 0))->text().split(' ').value(1) + "';");
            	QSqlQuery deleteFromPilots(deletePilot, QSqlDatabase::database("dataB"));
            	deleteFromPilots.finish();
            	
            }
            
            //Function to update table's structure
            void pickParticipants::updateTableStructure() {
            	
            	//Saving drivers' IDs before clearing the table
            	this->saveDrivers();
            	//Clearing view, including headers and selections
            	ui.driversTable->clear();
            
            	//Setting up the new structure
            	this->setRaceTableStructure();
            
            	//Setting the number of labels
            	ui.driversTable->setColumnCount(4);
            	//Inserting the labels
            	ui.driversTable->setHorizontalHeaderLabels(labelList);
            
            	//Connecting the listeners to race-related functions
            	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deleteRace()));
            	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewRaceFcn()));
            	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(openResults()));
            
            	labelList.~QStringList();
            	//Populating the table with races
            	this->populateRacesTable();
            
            }
            
            											// Races part
            
            void pickParticipants::addNewRaceFcn() {
            	//Set up the window
            	addNewRace addRaceWindow;
            	addRaceWindow.setModal(true);
            	//Show the window
            	addRaceWindow.exec();
            }
            
            void pickParticipants::deleteRace() {
            
            	int selectedRow;
            
            	for (QTableWidgetItem* selectedItem : ui.driversTable->selectedItems()) {
            		if ((*selectedItem).isSelected()) {
            			selectedRow = (*selectedItem).row();
            			break;
            		}
            	}
            
            	//Delete car from database using selected row 
            	QString deleteRace("DELETE FROM Curse WHERE locatie = '" + (ui.driversTable->item(selectedRow, 0))->text() + "' AND lungime = " + (ui.driversTable->item(selectedRow, 0))->text() + ";");
            	QSqlQuery deleteFromRaces(deleteRace, QSqlDatabase::database("dataB"));
            	deleteFromRaces.finish();
            }
            
            void pickParticipants::openResults() {
            	
            	this->saveRaces();
            
            	//moving to the next screen "resultPage"
            		//hide the "Pick Races" UI
            	this->hide();
            	//set the new page "PickParticipants"
            	resultPage resultPageUI;
            	resultPageUI.setModal(true);
            	//show the new page
            	resultPageUI.exec();
            }
            
            
            void pickParticipants::populateRacesTable() {
            	//Cleaning the table
            	ui.driversTable->setRowCount(0);
            
            	//Open the database and fetch table entries
            	if (QSqlDatabase::database("dataB").open()) {
            		//SQL Query that fetches all the pilots along with their team and car specs
            		QString selectAllRaces("SELECT locatie, numar_ture, lungime FROM Curse;");
            		//Execute "selectAllPilots" query against "dataB" database
            		QSqlQuery qry(selectAllRaces, QSqlDatabase::database("dataB"));
            
            		//Count the number of records
            		int rowCounter = 0;
            
            		qry.first();
            		//Build drivers table
            		while (qry.next()) {
            			ui.driversTable->insertRow(rowCounter);
            
            			//we use "ui.driversTable->columnCount() - 1" because last column is a checkbox
            			for (int colCounter = 0; colCounter < ui.driversTable->columnCount() - 1; colCounter++) {
            				ui.driversTable->setItem(rowCounter, colCounter, new QTableWidgetItem(qry.value(colCounter).toString()));
            			}
            
            			//TO-DO insert the checkbox in the last column
            			QTableWidgetItem* checkboxItem = new QTableWidgetItem();
            			checkboxItem->setCheckState(Qt::Unchecked);
            			ui.driversTable->setItem(rowCounter, ui.driversTable->columnCount() - 1, checkboxItem);
            			//move to the next row
            			rowCounter++;
            		}
            
            		qry.finish();
            	}
            }
            
            
            //Function to save selected drivers' IDs in vector
            void pickParticipants::saveDrivers() {
            
            	//Query to fetch driver's Id using name
            	QString selectDriverIdByName("SELECT ID_Pilot FROM Piloti WHERE nume = '");
            	for (int rowIterator = 0; rowIterator < ui.driversTable->rowCount(); rowIterator++) {
            		if (ui.driversTable->item(rowIterator, ui.driversTable->columnCount() - 1)->checkState()) { //Pick every driver with checkbox's checkState == 'Checked'(2)
            			//Fetching driver's name from the table
            			QString driverName = ui.driversTable->item(rowIterator, 0)->text() + "';";
            			//Fetching ID from the database and appending it in the drivers' vector
            			QSqlQuery qry(selectDriverIdByName + driverName, QSqlDatabase::database("dataB"));
            			qry.first();
            			driversIdVector.append(qry.value(0).toInt());
            			
            			qry.~QSqlQuery();
            		}
            	}
            }
            
            //Function to save selected races' IDs in vector
            void pickParticipants::saveRaces() {
            
            	//Query to fetch driver's Id using name
            	QString selectRaceIdByLocation("SELECT ID_Cursa FROM Curse WHERE locatie = '");
            	for (int rowIterator = 0; rowIterator < ui.driversTable->rowCount(); rowIterator++) {
            		if (ui.driversTable->item(rowIterator, ui.driversTable->columnCount() - 1)->checkState() == 2) { //Pick every race with checkbox's checkState == 'Checked'(2)
            			//Fetching race's location from the table
            			QString raceLocation = ui.driversTable->item(rowIterator, 0)->text() + "';";
            			//Fetching ID from the database and appending it in the race' vector
            			QSqlQuery qry(selectRaceIdByLocation + raceLocation, QSqlDatabase::database("dataB"));
            			qry.first();
            			racesIdVector.append(qry.value(0).toInt());
            
            			raceLocation.~QString();
            		}
            	}
            }
            
            void pickParticipants::setRaceTableStructure() {
            	
            	//Label list for the Races Table 
            	QStringList labelList = { "Location", "Laps", "Length", "To Tournament" };
            	
            	//Setting the number of labels
            	ui.driversTable->setColumnCount(4);
            	//Inserting the labels
            	ui.driversTable->setHorizontalHeaderLabels(labelList);
            
            	//Connecting the listeners to race-related functions
            	connect(ui.deletePushButton, SIGNAL(clicked()), this, SLOT(deleteRace()));
            	connect(ui.addPushButton, SIGNAL(clicked()), this, SLOT(addNewRaceFcn()));
            	connect(ui.okPushButton, SIGNAL(clicked()), this, SLOT(openResults()));
            
            	labelList.~QStringList();
            
            }
            

            The error is shown on this->setRaceTableStructure(); inside the void pickParticipants::updateTableStructure() method.

            Call stack:

             	ntdll.dll!RtlpBreakPointHeap()	Unknown
             	ntdll.dll!RtlpValidateHeapEntry()	Unknown
             	ntdll.dll!RtlValidateHeap()	Unknown
             	KernelBase.dll!HeapValidate()	Unknown
             	ucrtbased.dll!_CrtIsValidHeapPointer(const void * block) Line 1407	C++
             	ucrtbased.dll!free_dbg_nolock(void * const block, const int block_use) Line 904	C++
             	ucrtbased.dll!_free_dbg(void * block, int block_use) Line 1030	C++
             	ucrtbased.dll!free(void * block) Line 32	C++
             	Qt5Cored.dll!00007ff899c90265()	Unknown
             	Qt5Cored.dll!00007ff899bf612e()	Unknown
             	Qt5Cored.dll!00007ff899bedac4()	Unknown
             	Qt5Cored.dll!00007ff899c511e7()	Unknown
             	Qt5Cored.dll!00007ff89a0c4e7a()	Unknown
             	Qt5Cored.dll!00007ff89a0cfcba()	Unknown
             	Qt5Cored.dll!00007ff89a0b8910()	Unknown
             	Qt5Cored.dll!00007ff89a0bfffc()	Unknown
             	Qt5Cored.dll!00007ff89a0aaf5e()	Unknown
             	Qt5Cored.dll!00007ff89a0a57f3()	Unknown
             	Qt5Widgetsd.dll!00007ff89b31171b()	Unknown
             	Qt5Widgetsd.dll!00007ff89b312527()	Unknown
             	Qt5Widgetsd.dll!00007ff89b31396a()	Unknown
             	Qt5Widgetsd.dll!00007ff89b314370()	Unknown
             	Qt5Widgetsd.dll!00007ff89b31168f()	Unknown
             	Qt5Widgetsd.dll!00007ff89b331686()	Unknown
             	F1_System.exe!QTableWidgetItem::`scalar deleting destructor'(unsigned int)	C++
             	Qt5Widgetsd.dll!00007ff89b339915()	Unknown
             	Qt5Widgetsd.dll!00007ff89b339837()	Unknown
             	Qt5Widgetsd.dll!00007ff89b334e29()	Unknown
            >	F1_System.exe!pickParticipants::updateTableStructure() Line 109	C++
             	F1_System.exe!pickParticipants::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 90	C++
             	[External Code]	
             	F1_System.exe!addNewTournament::openPilotsTeamsCars() Line 35	C++
             	F1_System.exe!addNewTournament::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 77	C++
             	[External Code]	
             	F1_System.exe!welcomePage::openAddNewTournamentWindow() Line 24	C++
             	F1_System.exe!welcomePage::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 78	C++
             	[External Code]	
             	F1_System.exe!F1_System::validateLogin() Line 40	C++
             	F1_System.exe!F1_System::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 76	C++
             	[External Code]	
             	F1_System.exe!main(int argc, char * * argv) Line 9	C++
             	F1_System.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 104	C++
             	[External Code]	
            
            

            Please, I really need some help on this...

            Thank you for your time!

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

            @Ovidiu_GCO said in Some error occuring on destructor:

            qry.~QSqlQuery();

            Why?!

            "labelList.~QStringList();" - again - Why?
            You should not call destructors like this (this is usually only done when using placement new). A destructor is called AUTOMATICALLY when the variable is destroyed.

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

            O 1 Reply Last reply
            3
            • jsulmJ jsulm

              @Ovidiu_GCO said in Some error occuring on destructor:

              qry.~QSqlQuery();

              Why?!

              "labelList.~QStringList();" - again - Why?
              You should not call destructors like this (this is usually only done when using placement new). A destructor is called AUTOMATICALLY when the variable is destroyed.

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

              @jsulm I was calling those destructors hoping they will solve the problem, but there is not the case. They didn't help in any way.

              Just commented those lines, the error is still there.

              Thanks!

              jsulmJ J.HilkJ 2 Replies Last reply
              0
              • O Ovidiu_GCO

                @jsulm I was calling those destructors hoping they will solve the problem, but there is not the case. They didn't help in any way.

                Just commented those lines, the error is still there.

                Thanks!

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

                @Ovidiu_GCO What is in this line:
                "pickParticipants::updateTableStructure() Line 109"

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

                1 Reply Last reply
                0
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #28
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • O Ovidiu_GCO

                    @jsulm I was calling those destructors hoping they will solve the problem, but there is not the case. They didn't help in any way.

                    Just commented those lines, the error is still there.

                    Thanks!

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

                    hi @Ovidiu_GCO ,
                    can you tell my way why your ui - instance is created on the stack and not the heap ? Seems like it was created automatically via QtCreator, if thats the case it is highly unusual behaviour.


                    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.

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

                      hi @Ovidiu_GCO ,
                      can you tell my way why your ui - instance is created on the stack and not the heap ? Seems like it was created automatically via QtCreator, if thats the case it is highly unusual behaviour.

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

                      @J.Hilk I designed the UI using QtCreator, but I do not know how to answer your "why" question.

                      J.HilkJ 1 Reply Last reply
                      0
                      • O Ovidiu_GCO

                        @J.Hilk I designed the UI using QtCreator, but I do not know how to answer your "why" question.

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

                        @Ovidiu_GCO
                        ah alright, you made the ui form independet from your class and than added it afterwards, alright.

                        PS. thanks, fixed the obvious typo :P


                        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
                        0

                        • Login

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