Restoring previous session of an application



  • 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



  • You could use QSettings for that.



  • 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



  • Nothing a little Google search won't tell you, I think? See "this":http://wiki.forum.nokia.com/index.php/TSQ001327_-_Qt_and_S60_settings_management_comparison, for example.



  • thanks andre,i got a brief overview..



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

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    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()
    {
    QSettings settings("Mycompany","Myapp");
    settings.beginGroup(MainWindow);
    settings.setValue("color",color());
    settings.endGroup();

    }
    void MainWindow::readSettings()
    {
    QSettings settings("Mycompany","Myapp");
    settings.beginGroup(MainWindow);
    color(settings.value("color",QColor("red")));
    }@

    regards
    imrrk



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

    regards
    imrrk



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



  • 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,this is a code snippet from docs,and i have some doubts here,can anybody explains me what is the 3 statement doing

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

    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>
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    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()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    QColor r("red");
    r.name();
    settings.setValue("color",r.name());
    settings.endGroup();
    }

    void MainWindow::readSettings()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    QColor r(settings.value("color").toString());
    settings.endGroup();
    }
    void MainWindow::closeEvent(QCloseEvent * event)
    {
    if(on_exit_clicked())
    {
    writeSettings();
    event->accept();
    }
    else
    event->ignore();

    }

    bool MainWindow::on_exit_clicked()
    {
    writeSettings();
    exit(0);
    }@

    regards
    imrrk



  • 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



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



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



  • [quote author="imrrk" date="1306306497"]
    @#include <QtCore/QCoreApplication>
    #include <QtGui/QCloseEvent>
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    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()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    QColor r("red");
    r.name();
    settings.setValue("color",r.name());
    settings.endGroup();
    }

    void MainWindow::readSettings()
    {
    QSettings settings("Moose Soft", "Clipper");

    settings.beginGroup("pushbutton");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    QColor r(settings.value("color").toString());
    settings.endGroup();
    }
    void MainWindow::closeEvent(QCloseEvent * event)
    {
    if(on_exit_clicked())
    {
    writeSettings();
    event->accept();
    }
    else
    event->ignore();

    }

    bool MainWindow::on_exit_clicked()
    {
    writeSettings();
    exit(0);
    }@

    regards
    imrrk[/quote]

    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



  • hello leon
    when i call it in constructor,then also it wont work..

    regards
    imrrk



  • Volker,I have tried so far and also i have pasted the code ,but according to you it might be very little as your r a qt geek..I just need a direction to proceed.

    Regards
    imrrk



  • I personally would do something with the color read from the settings....



  • Hi volker thanks for your reply,you mean to say that

    @QColor r("red");
    r.name();
    settings.setValue("color",r.name());@

    I should check these lines..?

    regards
    imrrk



  • no.



  • Then?which lines i have to check.

    regards
    imrrk



  • Think yourself. It's obvious....



  • ok.I think these lines then...
    QColor r(settings.value("color").toString());

    am I right?

    regards
    imrrk



  • You're heading towards one of the hotspots...



  • Hi imrrk,

    one suggestion:

    look at the docs of QColor and QSettings.
    Then you should find it.

    Regards

    Gerolf



  • hello Volker,I am sorry,I didnt get your meaning..

    Hello gerolf, from yesterday i am reading the docs..
    this has been given

    @QSettings settings("MySoft", "Star Runner");
    QColor color = palette().background().color();
    settings.setValue("DataPump/bgcolor", color);@
    //here i didnt understand "DataPump/bgcolor"..

    regards
    imrrk



  • Hello Volker and gerolf,
    whether it should be done this way..

    QColor r(settings.value(“color”).toString(),ui->pushbutton->setcolor(r));

    regards
    imrrk



  • Hi imrrk,
    You get a lot of help here, so please dont email me for something like this.



  • ok ,Whether I am heading the correct way..?

    regards
    imrrk



  • immrk, is all this work for a school assignment or an actual job?



  • [quote author="imrrk" date="1306333461"]ok ,Whether I am heading the correct way..?
    [/quote]

    no.



  • hello Volker,Can u give me some hints then..

    regards
    imrrk



  • [quote author="imrrk" date="1306387710"]hello Volker,Can u give me some hints then..[/quote]

    To quote myself:

    [quote author="Volker" date="1306322983"]I personally would do something with the color read from the settings....[/quote]

    Oh, and that debugger thingie likes breakpoints, you know...

    I would be alarmed if it did not stop at a certain point....



  • hello volker problem solved..now i m able to set colors..and save it in .ini file

    @void MainWindow::writeSettings()
    {
    QSettings settings;//("company name", "project");

    settings.beginGroup("pushbutton");
    settings.setValue("size", size());
    settings.setValue("pos", pos());
    settings.setValue("mytext",ui->pushButton->styleSheet());
    settings.setValue("mytext1",ui->pushButton_2->styleSheet());
    settings.setValue("mytext2",ui->pushButton_3->styleSheet());
    //QColor r("red");
    //r.name();

    //settings.setValue("color",r.name());

    settings.setValue("state", saveState());
    qDebug()<<r.name();
    settings.endGroup();
    }

    void MainWindow::readSettings()
    {
    QSettings settings;//("Plackal", "restoreproject");

    settings.beginGroup("pushbutton");
    resize(settings.value("size", QSize(400, 400)).toSize());
    move(settings.value("pos", QPoint(200, 200)).toPoint());
    a=settings.value("mytext").toString();
    b=settings.value("mytext1").toString();
    c=settings.value("mytext2").toString();
    //ui->pushButton->setText(a);
    //QColor r=settings.value("color").toString();
    ui->pushButton->setStyleSheet(a);
    ui->pushButton_2->setStyleSheet(b);
    ui->pushButton_3->setStyleSheet(c);
    //ui->pushButton->autoFillBackground(r);
    QByteArray state = settings.value("state", QByteArray()).toByteArray();
    restoreState(state);
    //resize(size);
    //move(pos);
    qDebug("set");
    settings.endGroup();

    }@

    regards
    imrrk



  • Hi All,

    Although this thread is generating too much spam I think the topic about QSettings is interesting. I was unable to find a simple QSettings example here in our wiki nor in Forum Nokia so I decided to create a new article:
    "How to Use QSettings":http://developer.qt.nokia.com/wiki/How_to_Use_QSettings I have tested the example on my Nokia E7 and I will improve the article in the coming days :)

    Best regards,
    Leon

    P.S.

    Please note that the example contains very basic GUI without any layouts. My idea was just to focus on the basic usage of QSettings.



  • I found the API docs on "QSettings":http://doc.qt.nokia.com/4.7/qsettings.html with the example snippets to be sufficient.



  • Thanks Leon for you support..:)

    Regards
    imrrk



  • [quote author="Volker" date="1306406061"]I found the API docs on "QSettings":http://doc.qt.nokia.com/4.7/qsettings.html with the example snippets to be sufficient.[/quote]

    Please excuse me if you find the article useless. Qt documentation is very good and there are examples for almost everything but I think it is always good to have another example application at Qt Dev Net wiki.

    10x,
    Leon



  • Oh, no insult intended. Every wiki article with a working snippet adds value to DevNet, IMHO.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.