Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Why does restoreGeometry return false?

[Solved]Why does restoreGeometry return false?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    crqt
    wrote on last edited by
    #1

    I have an application that saves its window state on shutdown using saveGeometry, and restores them on startup using restoreGeometry, all persisted using QSettings.

    This aspect works just fine.

    However, I'm now trying to implement the ability to restore the application to its 'default' state via a menu action. What I'm finding is that when the application is in the state where I'm trying to do this, restoreGeometry returns false.
    I'd guess that this is the expected behavior, but if that's the case, how can I cause my widget to re-layout its components after it has already been displayed?

    Thanks.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goblincoding
      wrote on last edited by
      #2

      Hi there, I have absolutely no problem in achieving what you're setting out to do, but I'm using restoreState(). Example snippets:

      @
      /* On first run, save the default settings to the registry/ini/xml. */
      QSettings settings( ORGANISATION, APPLICATION );

      if( !settings.contains( "defaultState" ) )
      {
      settings.setValue( "defaultState", saveState() );
      }
      @

      And then simply connect your action to a slot such as:

      @
      void MainWindow::restoreDefaults()
      {
      QSettings settings( ORGANISATION, APPLICATION );
      restoreState( settings.value( "defaultState" ).toByteArray() );
      }
      @

      http://www.goblincoding.com

      1 Reply Last reply
      0
      • C Offline
        C Offline
        crqt
        wrote on last edited by
        #3

        Thanks for your response, it helped me realize that it was the contents of the restoreGeometry (and restoreState) function calls that I was making that was causing it to return false, rather than the "state" that the application was in.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goblincoding
          wrote on last edited by
          #4

          Good stuff! :)

          Please edit your original post and mark the thread as "Solved" ;)

          http://www.goblincoding.com

          1 Reply Last reply
          0
          • C Offline
            C Offline
            crqt
            wrote on last edited by
            #5

            for posterity, I was doing a
            @ Settings.remove("key")@

            followed by a

            @restoreState(settings.value( "key" ).toByteArray() )@
            In an attempt to restore to the default, which didn't work.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved