Results 1 to 11 of 11

Thread: QMainWindow : restorestate problems

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QMainWindow : restorestate problems

    Hello,

    i save the state of my main window and when i restore it's state it is not working well
    my window contains some docked widgets
    when i close a dockedWidget it creates a QPlaceHolderItem
    and this QPlaceHolderItem is written in that byteArray that QmainWindow::savestate returns
    and i think this is why if i have 2 docked widgets of the same type and one is closed
    then i click save and then
    when i restore the state none of them are showed , because QPlaceHolderItem messes things up .[i think]


    Thanks.
    Last edited by fmariusd; 19th October 2009 at 16:45.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMainWindow : restorestate problems

    Are the object names of your dock widgets unique?

  3. #3
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWindow : restorestate problems

    yes they are

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMainWindow : restorestate problems

    Ok, sorry for asking "stupid" questions, but normally it should work, so how do you save the state? Do you use QSettings for that or do you write the QByteArray yourself in a file? Maybe during saving and writing the bytes get corrupted. How your saving and lading looks like? And by the way which version of Qt do you use?

  5. #5
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QMainWindow : restorestate problems

    You are not asking stupid questions
    I use QSettings and Qt 4.5.1

    this is when i save the state

    Qt Code:
    1. trdset.beginGroup("General");
    2. trdset.setValue("STATE", saveState());
    3. trdset.setValue("GEOM", saveGeometry());
    4. trdset.endGroup();
    5. trdset.sync();
    To copy to clipboard, switch view to plain text mode 

    loading the settings :
    Qt Code:
    1. loadFunction (QSettings& trdset)
    2. {
    3.  
    4. trdset.beginGroup("General");
    5. QByteArray layout_data = trdset.value("STATE").toByteArray();
    6. bool b= restoreState(layout_data);
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 


    I have put some breakpoints in qdockarealayout.cpp and i can see that when i save the state the code is saveing the qplaceholderitems too (qplaceholderitems for the closed docked widgets )

    qdockarealayout.cpp : (it is entering this if when i save the state)
    Qt Code:
    1. else if (item.placeHolderItem != 0) {
    2. stream << (uchar) WidgetMarker;
    3. stream << item.placeHolderItem->objectName;
    4. uchar flags = 0;
    5. ....
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QMainWindow : restorestate problems

    i re -edited my first post :
    .... and i think this is why if i have 2 docked widgets of the same type and one is closed
    then i click save and then
    when i restore the state none of them are showed , because QPlaceHolderItem messes things up .[i think]

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMainWindow : restorestate problems

    Ok, I have tested it with various versions here and couldn't reproduce your problem. I have attached a project, please compile it and check if the error occurs even with that simple test application. Then we will see...
    Attached Files Attached Files

  8. The following user says thank you to Lykurg for this useful post:

    fmariusd (20th October 2009)

  9. #8
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QMainWindow : restorestate problems

    the difference between ur code mine is that i have this property set for the dockwidgets:

    Qt Code:
    1. ui->d1->setAttribute(Qt::WA_DeleteOnClose, true);
    2. ui->d2->setAttribute(Qt::WA_DeleteOnClose, true);
    To copy to clipboard, switch view to plain text mode 

    and i create them at runtime , and now it's almost working:

    each time i close a dockwidget i must :

    Qt Code:
    1. removeDockWidget(dk);
    To copy to clipboard, switch view to plain text mode 

    can i work with restore state like this?

  10. #9
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question how to delete not used placeholderitems

    i think i need a way to delete not used placeholderitems if someone knows ....

  11. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMainWindow : restorestate problems

    Quote Originally Posted by fmariusd View Post
    and i create them at runtime
    From the docs:
    bool QMainWindow::restoreDockWidget ( QDockWidget * dockwidget )
    Restores the state of dockwidget if it is created after the call to restoreState(). Returns true if the state was restored; otherwise returns false.
    Did this works?

  12. #11
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: QMainWindow : restorestate problems

    that didn't work , when recreating the layout i had to recreate all the widgets even the deleted ones and than delete those once again and let just those which weren't closed when saving the state

Similar Threads

  1. QMainWindow with QMainWindow
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2011, 08:07
  2. Replies: 1
    Last Post: 21st November 2008, 08:00
  3. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 14:00
  4. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 08:16
  5. Replies: 18
    Last Post: 22nd February 2006, 21:51

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.