Results 1 to 4 of 4

Thread: saving the state of the ui

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default saving the state of the ui

    hi,

    I wonder if there is possible to return the .ui class initial state. Actually, I want to change the contents of the ui file by a button click and I want the ui file come back to it's initial state just after another button click in the same window.

    is this possible?

    thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: saving the state of the ui

    You can save all properties of all widgets in a window and then reset them back when you need it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: saving the state of the ui

    I think QSettings is very convenient for such tasks.

  4. #4
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: saving the state of the ui

    To save a state use something like:

    Qt Code:
    1. QSettings settings( "MyIniFile.ini", QSettings::IniFormat );
    2. settings.beginGroup( "MyGroup" );
    3. settings.setValue( "MyStateName", saveState(0) );
    4. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    To restore it use:

    Qt Code:
    1. QSettings settings( "MyIniFile.ini", QSettings::IniFormat );
    2. settings.beginGroup( "MyGroup" );
    3. restoreState( settings.value( "MyStateName", QByteArray() ).toByteArray(), 0 );
    4. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    I develop mainly on Windows but prefer the INI storage format as it doesn't intefere with the registry and can be easily edited by hand (with the exception of states...).

    You'll need to change your ini, group and state names accordingly (all the strings).

    For more detailed work refer to QSettings.

    Hope this helps.
    Last edited by Paladin12; 24th March 2009 at 12:25. Reason: updated contents

Similar Threads

  1. QToolbar and restoring state
    By roxton in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2008, 20:35
  2. Storing widget state
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2008, 09:55
  3. Saving state of connections
    By Chuk in forum Qt Programming
    Replies: 11
    Last Post: 26th August 2007, 17:01
  4. Replies: 1
    Last Post: 24th June 2006, 11:10
  5. [QT4] Saving a widget state
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2006, 14:31

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.