Restoring previous session of an application
Page |
1 |
Hello friends,I am developing an mobile application where i will require to perform some operations which will be represented in from of colors,suppose i set colors for pushbutton,now when i close my application,and again open it.I want to restore the same session,i mean the colors which i had set before closing the application should remain as it is..So may i know how to do this .
regards
imrrk
40 replies
Nothing a little Google search won’t tell you, I think? See this [wiki.forum.nokia.com], for example.
Hello everyone,I have tried something with regards to Qsettings,I request you to please help me out and tell me whether i am proceeding in correct direction.
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QSettings>
- #include <QtCore/QCoreApplication>
- {
- ui->setupUi(this);
- writeSettings();
- readSettings();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- function to set the colors for the pushbutton..
- void MainWindow::on_click_clicked()
- {
- //three pushbuttons
- ui->pushButton->setStyleSheet("{color: red;}");
- ui->pushButton_2->setStyleSheet("{background-color: green;}");
- ui->pushButton_3->setStyleSheet("{background-color: yellow;}");
- }
- void MainWindow::writeSettings()
- {
- settings.beginGroup(MainWindow);
- settings.setValue("color",color());
- settings.endGroup();
- }
- void MainWindow::readSettings()
- {
- settings.beginGroup(MainWindow);
- }
regards
imrrk
hey vinb,thanks for ur help,I didnt get you will u please ellaborate..Actually as you see the code at first run I will set the background color on each of the 3 pushbuttons,and close the appplication and again when i open the application ,i should get the same state i.e the colors should be already present
regards
imrrk
Hello friends,I have written the below code to save my settings using qsettings and when i again open it,i should get the same state,but the values are not saved,,please help me out in this regard..
- #include <QtCore/QCoreApplication>
- #include <QtGui/QCloseEvent>
- {
- ui->setupUi(this);
- // readSettings();
- // writeSettings();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }void MainWindow::on_click_clicked()
- {
- ui->pushButton->setStyleSheet("color: red;");
- ui->pushButton_2->setStyleSheet("background-color: green;");
- ui->pushButton_3->setStyleSheet("background-color: yellow;");
- }
- void MainWindow::writeSettings()
- {
- settings.beginGroup("pushbutton");
- settings.setValue("size", size());
- settings.setValue("pos", pos());
- r.name();
- settings.setValue("color",r.name());
- settings.endGroup();
- }
- void MainWindow::readSettings()
- {
- settings.beginGroup("pushbutton");
- settings.endGroup();
- }
- {
- if(on_exit_clicked())
- {
- writeSettings();
- event->accept();
- }
- else
- event->ignore();
- }
- bool MainWindow::on_exit_clicked()
- {
- writeSettings();
- exit(0);
- }
regards
imrrk
#include <QtCore/QCoreApplication> #include <QtGui/QCloseEvent> { ui->setupUi(this); // readSettings(); // writeSettings(); } MainWindow::~MainWindow() { delete ui; }void MainWindow::on_click_clicked() { ui->pushButton->setStyleSheet("color: red;"); ui->pushButton_2->setStyleSheet("background-color: green;"); ui->pushButton_3->setStyleSheet("background-color: yellow;"); } void MainWindow::writeSettings() { settings.beginGroup("pushbutton"); settings.setValue("size", size()); settings.setValue("pos", pos()); r.name(); settings.setValue("color",r.name()); settings.endGroup(); } void MainWindow::readSettings() { settings.beginGroup("pushbutton"); settings.endGroup(); } { if(on_exit_clicked()) { writeSettings(); event->accept(); } else event->ignore(); } bool MainWindow::on_exit_clicked() { writeSettings(); exit(0); }regards
imrrk
Hi imrrk,
Where do you call readSettings()? It is commented out at the constructor.
Regards,
Leon
Posting in this timeline:
- 2 hours, 36 minutes ago
- 2 hours, 19 minutes ago
- 22 minutes ago
Do you really expect being taken serious when crying like a childish kiddie? Come on, get serious!
And look at your code if it is ever able to do what you expect it to do!
Or better: Use a debugger, set breakpoints and step through the code. You will find the error yourself then within seconds.
Hopefully nobody will tell you the solution here, as it has no learning effect.
EDIT: wrong read of code, sorry
You must log in to post a reply. Not a member yet? Register here!





