Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Ubuntu Unity and saving/restoring desktop apps
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)
qDebug() << "X: " << this->x() << ", Y: " << this->y();
qDebug() << "diff: " << this->frameGeometry().height() - this->geometry().height();
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.
andreyc last edited by
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
Do these examples move window on restore?
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 is run in a function upon app startup.
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.