Some error occuring on destructor
-
@Ovidiu_GCO
Hi
Ehh that seems completely unrelated to the code, i must say.
if you //QSqlDatabase::database("dataB").close();
does it still happen ? -
@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 -
@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?
-
@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. -
@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. -
Hi,
When the
addNewPilot_Button
function ends which is exactly afteraddPilotWindow.show()
is called. -
@Ovidiu_GCO Why don't you simply use exec() instead of show()?
-
@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!
-
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).
-
@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 Cmalloc
/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.... -
@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!
-
Unrelated to the problem at hand but why not use a QTableView / QSqlTableModel or QSqlQueryModel combo ?
-
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.
-
@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?
-
@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?
-
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 explicitnew
, so equally there is an implicit destruction when the local variable goes out of scope even though you have no explicitdelete
. 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.