Solved program crashes after assigning values to array elements
-
@jsulm said in program crashes after assigning values to array elements:
yes
if rowscount = 20 in for loop i have:for(int i = 0; i < count; i++){
meaning that maximum i = 19
although that is for safe side.
the number of rows in my tests is less than 10 -
@rezaMSLM To be sure: if on_pushButton_apply_clicked() is not executed there is no crash?
If so what happens if you comment outm_address.WaterMeterIDs[i][j] = ui->tableWidget->item(i,j)->text().toInt();
?
And do you use m_address.WaterMeterIDs somewhere else? -
@rezaMSLM Do you have any pointer or member variable that doesn't have a default value. It doesn't crash in "Debug" mode because Debug mode initializes a few things and release mode doesn't. Hope this helps you in figuring out what is wrong :)
-
@jsulm said in program crashes after assigning values to array elements:
what happens if you comment out
m_address.WaterMeterIDs[i][j] = ui->tableWidget->item(i,j)->text().toInt();if comment this, will not crash
@jsulm said in program crashes after assigning values to array elements:
And do you use m_address.WaterMeterIDs somewhere else?
no
-
@rezaMSLM Well, then the only idea I have is that you're writing outside of the array boundaries.
-
@rezaMSLM can you add another qDebug before m_address.WaterMeterIDs[i][j] = ui->tableWidget->item(i,j)->text().toInt();
qDebug() << i << j;
-
@Maaz-Momin said in program crashes after assigning values to array elements:
Do you have any pointer or member variable that doesn't have a default value
only WaterMeterIDs[20][2] has not initial value
-
@Maaz-Momin said in program crashes after assigning values to array elements:
@rezaMSLM can you add another qDebug before m_address.WaterMeterIDs[i][j] = ui->tableWidget->item(i,j)->text().toInt();
qDebug() << i << j;
added it.
the log is correct
and then crashes with one click anywhere -
@rezaMSLM can you make a minimal compileable example, so that we could test it?
-
@rezaMSLM I now believe the issue is different here. As you say, you resize or click... That means a paint is called. I guess your table index or a pointer is getting invalid. Can only understand after looking into code, can you share it?
-
@Maaz-Momin said in program crashes after assigning values to array elements:
@rezaMSLM I now believe the issue is different here. As you say, you resize or click... That means a paint is called. I guess your table index or a pointer is getting invalid. Can only understand after looking into code, can you share it?
@J.Hilk said in program crashes after assigning values to array elements:
can you make a minimal compileable example, so that we could test it?
yes
I will make a minimal compilable example and share it -
https://ufile.io/g2azi
I built a minimal compilable example that only read table cells and put them in array elements.
it doesn't crashes!
so I uploaded my current crashing program.
after run choose setaddres from parameters menu and then set number of rows with spinbox and click set button
then fill cells and then click apply.
if for first time program didn't crashed close it and re run -
@rezaMSLM It did not compile on my Linux machine until I fixed all wrong connect() calls.
It does not crash here, not in debug and not in release mode. -
@jsulm said in program crashes after assigning values to array elements:
It does not crash here, not in debug and not in release mode.
on my pc also doesn't crash some times
set number of rows to something near 20 like 17
and test it several times(each time close all windows and run it again) -
@rezaMSLM
same for my MacOS machineDoesn't compile until connects are fixed -> no crash on apply or after apply and resizing the window.
However the buttons ok and cancel have no effect, not sure if that's intended.
-
@rezaMSLM What I don't understand: why do you use an array (which has fixed size) to store elements from a table which has dynamic size? Why not use a QVector for that?
-
@jsulm said in program crashes after assigning values to array elements:
@rezaMSLM What I don't understand: why do you use an array (which has fixed size) to store elements from a table which has dynamic size? Why not use a QVector for that?
I will do it
but when I got crashes in the program focused on finding the cause.
then I will go to next step and use dynamic array. -
here is a video from the program crash on my pc
https://ufile.io/2o2co -
@rezaMSLM nope
followed the video to a T and no crash.Try deleting your build folder for a clean rebuild, also what qt version and compiler are you using?
-
@J.Hilk said in program crashes after assigning values to array elements:
@rezaMSLM nope
followed the video to a T and no crash.Try deleting your build folder for a clean rebuild, also what qt version and compiler are you using?
qt5.9.6
mingw5.3