Results 1 to 4 of 4

Thread: Problem in restoring more than one QDockWidget

  1. #1
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem in restoring more than one QDockWidget

    Hello,
    I have a mw with 2 dockwidget that I'd like to restore at start.
    Here is the code I use:

    Qt Code:
    1. dockInfo = new DockWindow(widgetInfo->windowTitle());
    2. addDockWidget(Qt::TopDockWidgetArea,dockInfo);
    3. dockInfo->setWidget(widgetInfo);
    4. dockInfo->hide();
    5.  
    6. dockScancella = new DockWindow(widgetScancella->windowTitle());
    7. addDockWidget(Qt::BottomDockWidgetArea,dockScancella);
    8. dockScancella->setWidget(widgetScancella);
    9. dockScancella->hide();
    10.  
    11. restoreState(stato);
    To copy to clipboard, switch view to plain text mode 
    and,during the closeEvent function I save the state of the window using
    Qt Code:
    1. stato=saveState();
    To copy to clipboard, switch view to plain text mode 
    and write it to file.

    Well, if I use 1 of the 2 dock widget (I mean I comment the code regarding the other) I have no problem and I can restore the whole system.
    If I use both the widgets, the bytearray representing the savingstate becomes more and more larger at each time I save the state. Moreover the widgets are nore restored correctly (they are restored randomly) in particular,sometimes, one of the 2 appears to be multiplied on screen and each copy is flickering.

    any hints?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in restoring more than one QDockWidget

    I could be totally off here, but could you verify what happens if you give each dock widget a unique name with setObjectName()? Also, try giving each dock widget a unique window title.
    Last edited by Chicken Blood Machine; 10th March 2006 at 17:14.
    Save yourself some pain. Learn C++ before learning Qt.

  3. #3
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in restoring more than one QDockWidget

    Quote Originally Posted by Chicken Blood Machine
    I could be totally off here, but could you verify what happens if you give each dock widget a unique name with setObjectName()? Also, try giving each dock widget a unique window title.
    Thanks for the answer but I'm yet using different object names and window titles.

  4. #4
    Join Date
    Feb 2006
    Location
    France (Metz)
    Posts
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem in restoring more than one QDockWidget

    Yop

    Maybe it is due to a problem of charachters conversion when you read/write to/from your saving file.

    Try to use the power of QSettings by doing something like that:

    Qt Code:
    1. //------------------------------------------------------------------------------
    2. /**
    3. */
    4. //------------------------------------------------------------------------------
    5. void
    6. MyMainWindow::saveWindowState()
    7. {
    8. QSettings l_settings("MyCompanyName", "MyAppName");
    9.  
    10. l_settings.beginGroup("MainWindow");
    11. l_settings.setValue("size", this->size());
    12. l_settings.setValue("pos", this->pos());
    13. l_settings.setValue("state", this->saveState());
    14. l_settings.endGroup();
    15. }
    16.  
    17. //------------------------------------------------------------------------------
    18. /**
    19. */
    20. //------------------------------------------------------------------------------
    21. void
    22. MyMainWindow::restoreWindowState()
    23. {
    24. QSettings l_settings("MyCompanyName", "MyAppName");
    25.  
    26. // Default size and position
    27. QRect l_rect = QApplication::desktop()->availableGeometry(0);
    28.  
    29.  
    30. l_settings.beginGroup("MainWindow");
    31. this->resize(l_settings.value("size", l_rect.size()).toSize());
    32. this->move(l_settings.value("pos", l_rect.topLeft()).toPoint());
    33. this->restoreState(l_settings.value("state", QByteArray()).toByteArray());
    34. l_settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    Works fine for me with 3 toolbars and about 6 dockwidgets...

    }

  5. The following 2 users say thank you to ldindon for this useful post:

    hyling (2nd November 2006), vratojr (13th March 2006)

Similar Threads

  1. QDockWidget magically disapear
    By 1111 in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 11:44
  2. Qt 4.4 QDockWidget resize problem
    By MarkSutton in forum Qt Tools
    Replies: 2
    Last Post: 27th September 2008, 08:55
  3. Replies: 1
    Last Post: 10th August 2008, 18:55
  4. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  5. QDockWidget nesting problem..
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 31st January 2007, 12:23

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.