2

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
}
Jérôme
  • 26,567
  • 29
  • 98
  • 120
iwatakeshi
  • 697
  • 3
  • 17
  • 31
  • have a look at this question : http://stackoverflow.com/q/3597900/2796, you should find the answer you are looking for regarding the usage of `QSettings`. – Jérôme Mar 09 '12 at 09:19
  • @Jérôme Thank you! :) I will keep that tabbed as a reference! – iwatakeshi Mar 09 '12 at 20:27

1 Answers1

4

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.

Manjabes
  • 1,884
  • 3
  • 17
  • 34
  • Really, wow, I was wondering what was the purpose for set value and how to use it. Now just a quick question to someone who started using qt a month ago lol, where you have `a.setOrganizationName()` and `a.setAplicationName()`. Will that overwrite the current names i.e. `MainWidow::setWindowTitle("example")`? – iwatakeshi Mar 09 '12 at 20:22