Results 1 to 7 of 7

Thread: 4.2 saveState

  1. #1
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 4.2 saveState

    Pieced together some quick POC code, but I believe it covers the major points. QDockWidgets do not appear to be saving state correctly with QMainWindow::saveState. Results vary with dock resizing, floating, and when not visible. I did not see this behavior in 4.1.4 open source, and tried to put together a quick poc rather then the large amount of code from my project for confirmation.

    I am not using MiniGW and am unclear if this is a problem with patches to the open source version, 4.2 changes, my horrid programing, or some change I am missing. The test I ran with the code example was on a WinXP system.

    main.h
    Qt Code:
    1. #ifndef _MAIN_H_
    2. #define _MAIN_H_
    3.  
    4. #include <QMainWindow>
    5. #include <QDockWidget>
    6. #include <QTextEdit>
    7.  
    8. class MainWindow : public QMainWindow {
    9.  
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow();
    14.  
    15. void readSettings();
    16. void writeSettings();
    17.  
    18. QTextEdit *textEdit;
    19.  
    20.  
    21. protected:
    22. void closeEvent(QCloseEvent *event);
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3.  
    4. #include "main.h"
    5.  
    6. MainWindow::MainWindow() {
    7.  
    8. textEdit = new QTextEdit;
    9. setCentralWidget(textEdit);
    10.  
    11. d1 = new QDockWidget(tr("Dock1"));
    12. d1->setObjectName(tr("d1"));
    13.  
    14. d2 = new QDockWidget(tr("Dock2"));
    15. d2->setObjectName(tr("d2"));
    16.  
    17. d3 = new QDockWidget(tr("Dock3"));
    18. d3->setObjectName(tr("d3"));
    19.  
    20. addDockWidget(Qt::RightDockWidgetArea, d1);
    21. addDockWidget(Qt::LeftDockWidgetArea, d2);
    22. addDockWidget(Qt::TopDockWidgetArea, d3);
    23.  
    24.  
    25. readSettings();
    26. }
    27.  
    28. void MainWindow::readSettings() {
    29.  
    30. QSettings settings("poc.ini",QSettings::IniFormat);
    31.  
    32. settings.beginGroup("session");
    33. restoreState(settings.value("Layout").toByteArray());
    34. QRect rect = settings.value("MainWindowGeometry",
    35. QRect(0, 0, 780, 520)).toRect();
    36. move(rect.topLeft());
    37. resize(rect.size());
    38. settings.endGroup();
    39. }
    40.  
    41. void MainWindow::writeSettings() {
    42.  
    43. QSettings settings("poc.ini",QSettings::IniFormat);
    44.  
    45. settings.beginGroup("session");
    46. settings.setValue("MainWindowGeometry", geometry());
    47.  
    48. settings.remove("Layout");
    49. settings.setValue("Layout",saveState());
    50. settings.endGroup();
    51.  
    52. }
    53.  
    54. void MainWindow::closeEvent(QCloseEvent *event)
    55. {
    56. writeSettings();
    57. event->accept();
    58. }
    59.  
    60. int main(int argc, char *argv[]) {
    61.  
    62. QApplication app(argc, argv);
    63. MainWindow mainwindow;
    64. mainwindow.show();
    65.  
    66. return app.exec();
    67. }
    To copy to clipboard, switch view to plain text mode 

    Some things you can try are:
    1. If you close a dock, and reload it will not remember it is closed.
    1a. Now if you had a dock nested in another and closed it, QMAinWindow::saveState will remember it was closed
    2. Moving a dock to another position will be remember.
    2a.Move a dock to another position and then close another, with 3 dockwidgets can cause all to be reset to default positioning.
    3. Float one dock and close another, will cause all 3 to reset to default positioning.
    Last edited by merlvingian; 16th October 2006 at 02:43. Reason: Added some tests to try

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 4.2 saveState

    In readSettings() : move the geometry restoration before restoreState() and see if it helps...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 4.2 saveState

    Quote Originally Posted by fullmetalcoder View Post
    In readSettings() : move the geometry restoration before restoreState() and see if it helps...
    No change

    Anyone with commercial 4.2 experiencing this behavior? I do not have access to a linux distro to test in that environment at this time.

  4. #4
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 4.2 saveState

    Anyone else able to produce this result from the code sample?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: 4.2 saveState

    Task Tracker - Entry 135551 - QMainWindow::saveState() doesn't save floating dockwidgets
    J-P Nurmi

  6. #6
    Join Date
    Sep 2006
    Posts
    46
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 4.2 saveState

    Quote Originally Posted by jpn View Post
    Task Tracker - Entry 135551 - QMainWindow::saveState() doesn't save floating dockwidgets
    It states it is in version 4.1.4 - I can not get the bug to reproduce in 4.1.4 open source only 4.2.0, unless it is referring to restoreState from a 4.0.1 save in 4.1.4.

    I will do some more research into the issue and see what is required in order to submit information to the task tracker.

    Thank you for your help on the issue.

  7. #7
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 4.2 saveState

    Reviving old thread. I'm using 4.3.2 so this bug should be fixed. However, my floating widgets don't show. When I show them, they have the right size and position but the visible flag doesn't seem to be saved.

    Any thoughts ?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.