Reputation: 697
I am currently creating a dialog with a check box that says "Do no display again". When the check box is clicked and the dialog is closed (ok button pressed), the application will store in QSettings
that this dialog box has been opened before.
I'm not familiar with Qt settings and looking at the API, I don't know which function to use.
Could anyone point me to the right direction? Thank you!
Btw I did try QErrorMessage
, but the message box keeps popping up so I gave up on it.
void MessageBox::on_checkBox_stateChanged(int arg1)
{
if(ui->checkBox->stateChanged(arg1) && ui->pushButton->clicked(true))
//I believe this is right.
{
writeSettings();
}
}
void MessageBox::writeSettings()
{
QSettings settings;
//...help; Question: Should I write in main.cpp or in the .h?
}
void MessageBox::readSettings()
{
//...help
}
Upvotes: 2
Views: 912
Reputation: 1904
To use the QSettings constructor in this form, you must set the organization and application name for your application, probably in main.cpp if you create it there:
QApplication a(argc, argv);
a.setOrganizationName("MySoft");
a.setApplicationName("Star Runner");
Then in your writeSettings() you do:
QSettings settings;
settings.setValue("showErrorMessages", ui->checkBox->isChecked());
and in readSettings()
QSettings settings;
bool showErrorMessages = settings.value("showErrorMessages", true).toBool()
It's all in the docs and explained quite clearly IMO.
Upvotes: 4