How can I enable the QDialogButtonBox
I am creating a GUI and I inserted in it a QDialogButtonBox in Designer.
I seek a function that enables the OK button (which should close the screen and save changes)
and a Cancel button (which should close the program and not save changes).
someone help me?
Select the button box, go to the property editor and scroll down until you find standardButtons, there you can select which one you want
But in this property only selects a button name and not a function to cancel and not save, for example.
From the "QDialogButtonBox help":http://qt-project.org/doc/qt-5/qdialogbuttonbox.html#details
"When a button is clicked in the button box, the clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole, RejectRole, or HelpRole, the accepted(), rejected(), or helpRequested() signals are emitted respectively."
You need to connect the signals, at least "clicked()":http://qt-project.org/doc/qt-5/qdialogbuttonbox.html#clicked to the slots in your class and process the buttons.
I created the signal:
@MainWindow::MainWindow(QWidget *parent) :
and the functions:
But has an error in connect:
error: invalid use of void expression.
How can I solve that?
If you create a slot from designer "Goto slot"/accepted, rejected then you don't need to connect them manually. So just delete two connect() lines and it should work.
If you prefer to connect manually then you connect call is not correct.
It should look like this
One way I found to solve my problem was to put in my function @ void MainWindow::on_buttonBox_accepted()
@ the execution to write in my text file and then used the @qApp->quit()@
And @ void MainWindow::on_buttonBox_rejected()
@ I put only the @qApp->quit()@ to close and not execute any writing in my file.