[SOLVED] saving the result of a check box
the qt library seems powerful. I am able to save the state and geometry of my window and dialogs. what is the best way to save the result of a check box? Can I save its state or do I need to save it to a file or some other method
15 replies
Can you show us your UI file ?
Also, see QSettings basic usage [doc.qt.nokia.com]
I fixed the code. now it does not give me an error but it still does not save the state of the check box
- #include "tipoftheday.h"
- #include "ui_tipoftheday.h"
- #include "mainwindow.h"
- #include <QDesktopWidget>
- #include <QSettings>
- #include <QCheckBox>
- ui(new Ui::TipOfTheDay)
- {
- ui->setupUi(this);
- this->setFixedSize(width(), height());
- QSettings settings;
- QCheckBox checkbox;
- checkbox.setChecked(settings.value("checkstate").toBool()); // load check-box state
- }
- TipOfTheDay::~TipOfTheDay()
- {
- delete ui;
- }
- void TipOfTheDay::on_checkBox_clicked()
- {
- QSettings settings;
- QCheckBox checkbox;
- settings.setValue("checkstate", checkbox.isChecked()); // save check-box state
- }
Hi kalster,
youi have a C++ error here:
you create a local QCheckbox on the stack, which will never show up anywhere and try to store it’s state. But instead, you have to reference to the one from the UI
This is standard in C++. A new variable will always create a new object, unless it’s not a reference (XXX&) or a pointer. Some specials are here for singletons or monostates, but that’s nothing for a UI.
You must log in to post a reply. Not a member yet? Register here!




