Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to reapply checkbox settings as stored in settings file



  • I have stored checkState() items from a QWidgetList(with Qt::ItemIsUserCheckable set) in a QSettings file that I would like to restore(including the CheckState. i have tried the following:

    QSettings *sttngs = new QSettings(QSettings::NativeFormat,QSettings::UserScope,"GNU","SCAPER",nullptr);
    nme_set(sttngs->value("name").toString());
    fname_set(sttngs->value("path").toString());
    sttngs->beginGroup("tooloptions");
    	
    list = new QListWidget(this);
    item = new QListWidgetItem(list);
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
    foreach(const QString &key, sttngs->childKeys()) {
    	Qt::CheckState state = (Qt::CheckState) sttngs->value(key).toInt();
    	item->setCheckState(state);
    	item->setText(key);
    	list->addItem(item);
    }
    

    but it only gives me one list item "unrecog" that is not part of the list stored in the QSettings file (~/.config/GNU/scaper/SCAPER.conf`)


  • Lifetime Qt Champion

    Hi,

    You are always re-adding the same item rather than creating a new one each time the loop iterates.


  • Lifetime Qt Champion

    Hi,

    You are always re-adding the same item rather than creating a new one each time the loop iterates.



  • @SGaist said in How to reapply checkbox settings as stored in settings file:

    Hi,

    You are always re-adding the same item rather than creating a new one each time the loop iterates.

    Uh! You're exactly right! Thanks for opening my eyes and pointing me in the right direction!


Log in to reply