May 23, 2011

imrrk imrrk
Lab Rat
216 posts

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

May 23, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

You could use QSettings for that.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

May 23, 2011

imrrk imrrk
Lab Rat
216 posts

Thanks gerolf,I will go through it,But i have question to u…As we have system registry on Windows, and in XML preferences files on Mac OS X. On Unix systems use INI text files.So in similar way whether we have registry for symbian also? and what it is called..?

regards
imrrk

May 23, 2011

Andre Andre
Area 51 Engineer
6031 posts

Nothing a little Google search won’t tell you, I think? See this [wiki.forum.nokia.com], for example.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 23, 2011

imrrk imrrk
Lab Rat
216 posts

thanks andre,i got a brief overview..

May 23, 2011

imrrk imrrk
Lab Rat
216 posts

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.

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QSettings>
  4. #include <QtCore/QCoreApplication>
  5.  
  6. MainWindow::MainWindow(QWidget *parent)
  7.     : QMainWindow(parent), ui(new Ui::MainWindow)
  8. {
  9.     ui->setupUi(this);
  10.   writeSettings();
  11.   readSettings();
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16.     delete ui;
  17. }
  18.  
  19. function to set the colors for the pushbutton..
  20. void MainWindow::on_click_clicked()
  21. {
  22.    
  23.     //three pushbuttons
  24.     ui->pushButton->setStyleSheet("{color: red;}");
  25.     ui->pushButton_2->setStyleSheet("{background-color: green;}");
  26.     ui->pushButton_3->setStyleSheet("{background-color: yellow;}");
  27. }
  28.  void MainWindow::writeSettings()
  29.  {
  30.    QSettings settings("Mycompany","Myapp");
  31.    settings.beginGroup(MainWindow);
  32.    settings.setValue("color",color());
  33.    settings.endGroup();
  34.      
  35.  }
  36. void MainWindow::readSettings()
  37. {
  38.     QSettings settings("Mycompany","Myapp");
  39.     settings.beginGroup(MainWindow);
  40.     color(settings.value("color",QColor("red")));
  41. }

regards
imrrk

May 24, 2011

imrrk imrrk
Lab Rat
216 posts

Hello friends,can anybody help me out,whether i am going in correct direction..

regards
imrrk

May 24, 2011

vinb vinb
Lab Rat
205 posts

write and read under eachother? (10,11)
line 40 looks strange, you read the setting using a string red?

May 24, 2011

imrrk imrrk
Lab Rat
216 posts

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

May 24, 2011

imrrk imrrk
Lab Rat
216 posts

Hello friends,this is a code snippet from docs,and i have some doubts here,can anybody explains me what is the 3 statement doing

  1.  QSettings settings("MySoft", "Star Runner");
  2.  QColor color = palette().background().color();
  3.  settings.setValue("DataPump/bgcolor", color);

regards
imrrk

May 25, 2011

imrrk imrrk
Lab Rat
216 posts

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..

  1. #include <QtCore/QCoreApplication>
  2. #include <QtGui/QCloseEvent>
  3. MainWindow::MainWindow(QWidget *parent)
  4.     : QMainWindow(parent), ui(new Ui::MainWindow)
  5. {
  6.     ui->setupUi(this);
  7.  
  8.   //  readSettings();
  9.      //   writeSettings();
  10.  
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15.     delete ui;
  16. }void MainWindow::on_click_clicked()
  17. {
  18.     ui->pushButton->setStyleSheet("color: red;");
  19.     ui->pushButton_2->setStyleSheet("background-color: green;");
  20.     ui->pushButton_3->setStyleSheet("background-color: yellow;");
  21. }
  22. void MainWindow::writeSettings()
  23. {
  24. QSettings settings("Moose Soft", "Clipper");
  25.  
  26. settings.beginGroup("pushbutton");
  27. settings.setValue("size", size());
  28. settings.setValue("pos", pos());
  29. QColor r("red");
  30. r.name();
  31. settings.setValue("color",r.name());
  32. settings.endGroup();
  33. }
  34.  
  35. void MainWindow::readSettings()
  36. {
  37. QSettings settings("Moose Soft", "Clipper");
  38.  
  39. settings.beginGroup("pushbutton");
  40. resize(settings.value("size", QSize(400, 400)).toSize());
  41. move(settings.value("pos", QPoint(200, 200)).toPoint());
  42. QColor r(settings.value("color").toString());
  43. settings.endGroup();
  44. }
  45. void MainWindow::closeEvent(QCloseEvent * event)
  46. {
  47.     if(on_exit_clicked())
  48.     {
  49.         writeSettings();
  50.         event->accept();
  51.     }
  52.     else
  53.         event->ignore();
  54.  
  55.  
  56. }
  57.  
  58. bool MainWindow::on_exit_clicked()
  59. {
  60.       writeSettings();
  61.       exit(0);
  62. }

regards
imrrk

May 25, 2011

imrrk imrrk
Lab Rat
216 posts

Hello friends any help would be appreciated,from yesterday i am trying out with QSettings,and the above code tells how much i got from it,might be it is very less..but i want to learn further and need your help..

regards
imrrk

May 25, 2011

imrrk imrrk
Lab Rat
216 posts

Hey friends,whether my code is correct,please guide me

May 25, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi imrrk, it will not help to post each hour.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

May 25, 2011

leon.anavi leon.anavi
Mad Scientist
1046 posts

imrrk wrote:

  1. #include <QtCore/QCoreApplication>
  2. #include <QtGui/QCloseEvent>
  3. MainWindow::MainWindow(QWidget *parent)
  4.     : QMainWindow(parent), ui(new Ui::MainWindow)
  5. {
  6.     ui->setupUi(this);
  7.  
  8.   //  readSettings();
  9.      //   writeSettings();
  10.  
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15.     delete ui;
  16. }void MainWindow::on_click_clicked()
  17. {
  18.     ui->pushButton->setStyleSheet("color: red;");
  19.     ui->pushButton_2->setStyleSheet("background-color: green;");
  20.     ui->pushButton_3->setStyleSheet("background-color: yellow;");
  21. }
  22. void MainWindow::writeSettings()
  23. {
  24. QSettings settings("Moose Soft", "Clipper");
  25.  
  26. settings.beginGroup("pushbutton");
  27. settings.setValue("size", size());
  28. settings.setValue("pos", pos());
  29. QColor r("red");
  30. r.name();
  31. settings.setValue("color",r.name());
  32. settings.endGroup();
  33. }
  34.  
  35. void MainWindow::readSettings()
  36. {
  37. QSettings settings("Moose Soft", "Clipper");
  38.  
  39. settings.beginGroup("pushbutton");
  40. resize(settings.value("size", QSize(400, 400)).toSize());
  41. move(settings.value("pos", QPoint(200, 200)).toPoint());
  42. QColor r(settings.value("color").toString());
  43. settings.endGroup();
  44. }
  45. void MainWindow::closeEvent(QCloseEvent * event)
  46. {
  47.     if(on_exit_clicked())
  48.     {
  49.         writeSettings();
  50.         event->accept();
  51.     }
  52.     else
  53.         event->ignore();
  54.  
  55.  
  56. }
  57.  
  58. bool MainWindow::on_exit_clicked()
  59. {
  60.       writeSettings();
  61.       exit(0);
  62. }

regards
imrrk

Hi imrrk,

Where do you call readSettings()? It is commented out at the constructor.

Regards,
Leon

 Signature 

http://anavi.org/

May 25, 2011

Volker Volker
Robot Herder
5428 posts

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

Page  
1

  ‹‹ Using QGraphicsItem in DLL.      subclassing widget to take coordinates ››

You must log in to post a reply. Not a member yet? Register here!