Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Restoring previous session of an application
Qt 6.11 is out! See what's new in the release blog

Restoring previous session of an application

Scheduled Pinned Locked Moved General and Desktop
41 Posts 7 Posters 38.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imrrk
    wrote on last edited by
    #7

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

    regards
    imrrk

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #8

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        imrrk
        wrote on last edited by
        #9

        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

        1 Reply Last reply
        0
        • I Offline
          I Offline
          imrrk
          wrote on last edited by
          #10

          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

          1 Reply Last reply
          0
          • I Offline
            I Offline
            imrrk
            wrote on last edited by
            #11

            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

            1 Reply Last reply
            0
            • I Offline
              I Offline
              imrrk
              wrote on last edited by
              #12

              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

              1 Reply Last reply
              0
              • I Offline
                I Offline
                imrrk
                wrote on last edited by
                #13

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #14

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

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

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    leon.anavi
                    wrote on last edited by
                    #15

                    [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

                    http://anavi.org/

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #16

                      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

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        imrrk
                        wrote on last edited by
                        #17

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

                        regards
                        imrrk

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          imrrk
                          wrote on last edited by
                          #18

                          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

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #19

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

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • I Offline
                              I Offline
                              imrrk
                              wrote on last edited by
                              #20

                              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

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #21

                                no.

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  imrrk
                                  wrote on last edited by
                                  #22

                                  Then?which lines i have to check.

                                  regards
                                  imrrk

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    goetz
                                    wrote on last edited by
                                    #23

                                    Think yourself. It's obvious....

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • I Offline
                                      I Offline
                                      imrrk
                                      wrote on last edited by
                                      #24

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

                                      am I right?

                                      regards
                                      imrrk

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        goetz
                                        wrote on last edited by
                                        #25

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

                                        http://www.catb.org/~esr/faqs/smart-questions.html

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          giesbert
                                          wrote on last edited by
                                          #26

                                          Hi imrrk,

                                          one suggestion:

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

                                          Regards

                                          Gerolf

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

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved