Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store settings of qt application using QSettings

Hello I have created an application using qt and I managed to save some of its settings using QSettings.

void DoneIt::writeSettings()
{
    QSettings settings("mycompany", "RightDoneIt");
    settings.beginGroup("DoneIt");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    settings.endGroup();
}

void DoneIt::readSettings()
{
    QSettings settings("mycompany", "RightDoneIt");
    settings.beginGroup("DoneIT");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    settings.endGroup();
}

That works fine with the window position and size. I have add some widgets in my application using the designer of qt and I would like to save their state too.

One of my widgets is a radio button and I call it radioButtonbnw

How can I save its state (checked or unchecked) ?

What are the best practises ?

like image 279
Sharethefun Avatar asked Nov 17 '10 04:11

Sharethefun


People also ask

Where are QT settings stored?

On Windows, NativeFormat settings are stored in the following registry paths: HKEY_CURRENT_USER\Software\MySoft\Star Runner. HKEY_CURRENT_USER\Software\MySoft\OrganizationDefaults. HKEY_LOCAL_MACHINE\Software\MySoft\Star Runner.


1 Answers

  1. Put them to QButtonGroup.
  2. Use QButtonGroup::setId to set Id for each radio button in this group.
  3. Save the Id of the checked button get by QButtonGroup::checkedId.
  4. Get the pointer of this button using QButtonGroup::button(id) when restore, and call QAbstractButton::setChecked.

BTW: if you want to saves the current state of mainwindow's toolbars and dockwidgets, use QMainWindow::saveState.

like image 149
2 revs, 2 users 67% Avatar answered Sep 24 '22 15:09

2 revs, 2 users 67%