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. Ubuntu Unity and saving/restoring desktop apps
Forum Updated to NodeBB v4.3 + New Features

Ubuntu Unity and saving/restoring desktop apps

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • M Offline
    M Offline
    medvedm
    wrote on last edited by
    #1

    Hi-

    When my application closes, I have overriden the closeEvent slot in my QMainWindow subclass and I do the suggested approach of using a QSettings to save the geometry and state like this:

    @
    void AcmeGroundDisplay::closeEvent(QCloseEvent *event)
    {
    _pSettings->setValue("geometry", this->saveGeometry());
    _pSettings->setValue("mainWindowState", this->saveState());
    _pSettings->setValue("positionX", this->x());
    _pSettings->setValue("positionY", this->y());

    qDebug() << "X: " << this->x() << ", Y: " << this->y();
    qDebug() << "diff: " << this->frameGeometry().height() - this->geometry().height();

    QMainWindow::closeEvent(event);
    }
    @

    I add the x and y variables for debugging because the problem is that every time I close and open the app, it restores the app slightly higher than the last time, such that eventually it is below the Unity to menu bar. Every time I close and it and open it, the Y value is 28 pixels less and I can't for the life of me figure out why. The difference is 36 (the frame size), so that isn't the problem.

    Of course, I use the restoreGeometry and restoreState functions when the app opens, and everything is correct except for the problem mentioned.

    I'm on Ubuntu 13.04, Qt 5.0.1. Anyone else seen anything like this? Very weird.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Did you check what is written to the settings file after you closed an application?
      Could you show how do you restore the settings.
      Also you can try to use the example from QMainWindow class "saveState":http://qt-project.org/doc/qt-5/qmainwindow.html#saveState and
      "restoreState":http://qt-project.org/doc/qt-5/qmainwindow.html#restoreState

      Do these examples move window on restore?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        medvedm
        wrote on last edited by
        #3

        My code is basically what is in those examples (I did it the way I did because of the example code).

        I'm not sure if you've ever looked at what save state and geometry look like in the file, but it is basically a bunch of binary gobbly-gook that isn't meant to be interpreted by people.

        In terms of restoring the window, it is very simple:

        @
        this->restoreGeometry(_pSettings->value("geometry").toByteArray());
        this->restoreState(_pSettings->value("mainWindowState").toByteArray());
        @

        This is run in a function upon app startup.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          medvedm
          wrote on last edited by
          #4

          Another weird data point. In my closeEvent function, I do an output of the difference between the frame geometry height and the normal geometry, and it changes between runs of the program! 29,36,29 etc.

          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