Program is crashing
-
@thomasGl said in Program is crashing:
QLabel *const helloWorldLabel; QPushButton *const beendeButton;
What's the reason for
const
? Remove theconst
@thomasGl said in Program is crashing:
delete helloWorldLabel; delete beendeButton;
also this can be removed... (child
QObjects
are deleted with their parent)and it should work.
Edit:
Initialized here:
MainWindow::MainWindow(QWidget *parent, QLabel *const helloWorldLabel, QPushButton *const beendeButton) : QMainWindow(parent) , helloWorldLabel(new QLabel("Hello World", this)) beendeButton(new QPushButton("Beenden", this))
-
@Pl45m4 said in Program is crashing:
Initialized here:
OMG, I hate that syntax and it's scrolled off the screen anyway... :( :) At minimum I wish people put newlines in like you show.
@JonB said in Program is crashing:
OMG, I hate that syntax and it's scrolled off the screen anyway... :( :)
Yup, reformatted it to make it somewhat readable.
What was the rule of thumb for maximum line length again? Until you get beaten as a programmer? :DD
Like 60-70 characters or so? ;-) -
Starting P:\Qt training\build-AktuellAktiv-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\AktuellAktiv.exe...
Warning: QT_DEVICE_PIXEL_RATIO is deprecated. Instead use:
QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors.
QT_SCREEN_SCALE_FACTORS to set per-screen factors.
QT_SCALE_FACTOR to set the application global scale factor.
The program has unexpectedly finished.
P:\Qt training\build-AktuellAktiv-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\AktuellAktiv.exe crashed. I am still getting that error -
Hi,
Please post the stack trace of the crash.
-
beendeButton -> setGeometry(30,30,30,30);
will call
setGeometry()
on the constructor argumentbeendeButton
, which defaults tonullptr
, because no argument is passed to the c'tor inmain.cpp
.I don't see, why this argument is necessary at all. Probably you get a compiler warning about an unused argument. Probably you expect
setGeometry
to be called on the member which you correctly initialize.=> remove the unneeded arguments from the c'tor. They are the reason for the crash.
-
@Axel-Spoerl thx it works now.
-
Remains the (unrelated) question, why you use Qt 5.9.0.
That ship has sailed long ago. Better use 6.5 or even 6.7. -
beendeButton -> setGeometry(30,30,30,30);
will call
setGeometry()
on the constructor argumentbeendeButton
, which defaults tonullptr
, because no argument is passed to the c'tor inmain.cpp
.I don't see, why this argument is necessary at all. Probably you get a compiler warning about an unused argument. Probably you expect
setGeometry
to be called on the member which you correctly initialize.=> remove the unneeded arguments from the c'tor. They are the reason for the crash.
@Axel-Spoerl said in Program is crashing:
will call setGeometry() on the constructor argument beendeButton, which defaults to nullptr, because no argument is passed to the c'tor in main.cpp.
Oh gosh.... haven't even seen that the argument is named exactly the same as the private member.
Thought there is something else going on, beside theconst
which is weird in this case, because the code didn't looked that wrong.@JonB Two blind people trying to help :D
Next time I scroll horizontally for you and you check the spelling for me :P -
@Axel-Spoerl said in Program is crashing:
will call setGeometry() on the constructor argument beendeButton, which defaults to nullptr, because no argument is passed to the c'tor in main.cpp.
Oh gosh.... haven't even seen that the argument is named exactly the same as the private member.
Thought there is something else going on, beside theconst
which is weird in this case, because the code didn't looked that wrong.@JonB Two blind people trying to help :D
Next time I scroll horizontally for you and you check the spelling for me :P -
@Pl45m4
I saw the formal parameters were the same names as the member variables, which made me wonder how that works. But I said I never use that syntax and thought I could trust you on this one ;-)@JonB said in Program is crashing:
I saw the formal parameters were the same names as the member variables, which made me wonder how that works. But I said I never use that syntax and thought I could trust you on this one ;-)
It would have, if only the names were different :'-)
In a regular function you would usethis->beendeButton(beendeButton)
, then the same names are not a problem anymore, but it does not work in initializer lists. -
m_beendeButton
…. and you’re set!