My program start to crash because of MessageBox
-
Hi
the call stack / trace it looks like this
-
Hey i just found that it work well if i put it in the constructor, so it crashes only when it in my other functions, strange.
UPDATE:
Here is info for everyone. Yesterday, i noticed that the app not just crashed, it crashed like.. twice, and all my app mostly about the use of "pressed" and "released" SLOTs of the buttons. I removed usage of release slot, and now app do just single crash. Here is how "release button" chain looks like:
void MainWindow::on_button_Q_released() { //lightRestore(currentButton); }
And here is that only function which it use:
void MainWindow::lightRestore(QPushButton *lamp) { lamp->setStyleSheet("QPushButton{color: white;background-color: rgb(35,35,35);border-style: outset;border-width: 2px;border-radius: 15px;border-color: black;font: bold 12px;}"); }
-
Hey i just found that it work well if i put it in the constructor, so it crashes only when it in my other functions, strange.
UPDATE:
Here is info for everyone. Yesterday, i noticed that the app not just crashed, it crashed like.. twice, and all my app mostly about the use of "pressed" and "released" SLOTs of the buttons. I removed usage of release slot, and now app do just single crash. Here is how "release button" chain looks like:
void MainWindow::on_button_Q_released() { //lightRestore(currentButton); }
And here is that only function which it use:
void MainWindow::lightRestore(QPushButton *lamp) { lamp->setStyleSheet("QPushButton{color: white;background-color: rgb(35,35,35);border-style: outset;border-width: 2px;border-radius: 15px;border-color: black;font: bold 12px;}"); }
@Engelard said in My program start to crash because of MessageBox:
currentButton
seems like currentButton is no longer a valid QPushButton-Pointer,
If you have a pointer member variable, you should make sure that you always set it to a nullptr when the pointed to object is destroyed/invalid.
And always check against that before accessing it:void MainWindow::lightRestore(QPushButton *lamp) { if(lamp) lamp->setStyleSheet(...); }
-
Hi, if I read the trace correctly, the user presses the button_G, that functions calls mainJourney() which issues the QMessageBox() call.
Could you show the code for mainJourney()?@hskoglund said in My program start to crash because of MessageBox:
Could you show the code for mainJourney()?
No, that stuff is too big, it called from pressButton SLOT, above much simplier and compact example of release, it does the same crash.
-
@Engelard said in My program start to crash because of MessageBox:
currentButton
seems like currentButton is no longer a valid QPushButton-Pointer,
If you have a pointer member variable, you should make sure that you always set it to a nullptr when the pointed to object is destroyed/invalid.
And always check against that before accessing it:void MainWindow::lightRestore(QPushButton *lamp) { if(lamp) lamp->setStyleSheet(...); }
@J.Hilk nice advice, tnx. But it valid(without that messageBox stuff everything works perfectly), i added if-check line. Nothing it changed(2nd crash exist).
UPDATE:
If i put messageBox AFTER assignment of that button - will be no crashes, but also it is not possible to hold the button(because this messageBox take over priority and it is now main waindow).
void MainWindow::on_button_Q_pressed() { currentButton = mainJourney('Q'); lightSet(currentButton); QMessageBox::information(nullptr, "ERROR", "trtrtr"); }
-
Oh, finally! With the help of @J-Hilk i realised what was wrong.
- add if-cheks in "lights" functions.
- assign currentButton to nullptr in the constructor. (i mistakenly thought that created pointers of the objects without assignment by default nullptr)
Now no crashes. Tnx @J-Hilk !