Results 1 to 4 of 4

Thread: saveState() problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default saveState() problem

    Can't seem to get this to work. I'm trying to save the mainwindow state to a database and restore it on startup so the window size and position will be the same as when the application was quit. The problem is that the size and positions don't get restored.

    Qt Code:
    1. // saving the state - this is called in the closeEvent:
    2. void MainWindow::saveSettings() {
    3. ba = saveState();
    4.  
    5. qDebug() << "saving ba size is " << ba.size();
    6.  
    7. QSqlDatabase db = QSqlDatabase::database(ctrlConn);
    8. QSqlQuery query(db);
    9. query.prepare("UPDATE settings set state=? where id=1");
    10. query.addBindValue(ba);
    11. query.exec();
    12.  
    13. qDebug() << "saving state " << query.lastError();
    14. }
    To copy to clipboard, switch view to plain text mode 
    saving ba size with debug shows 93

    Now restoring the state called from the constructor.
    Qt Code:
    1. void MainWindow::restoreSettings() {
    2. QSqlDatabase db = QSqlDatabase::database(ctrlConn);
    3. QSqlQuery query(db);
    4. query.exec("SELECT state from settings where id = 1");
    5. query.last();
    6. QByteArray ba = query.value(0).toByteArray();
    7.  
    8. qDebug() << "restoring ba size is " << ba.size();
    9.  
    10. restoreState(ba);
    11.  
    12. qDebug() << "restoring state " << query.lastError();
    13. }
    To copy to clipboard, switch view to plain text mode 

    debug shows restore state ba size is 93.
    What's wrong here?
    Last edited by waynew; 29th January 2010 at 01:29.

Similar Threads

  1. QDockWidget saveState and restoreState
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 28th January 2016, 09:56
  2. QHeaderView saveState()
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 26th December 2009, 15:46
  3. saveState with multiple windows
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 09:16
  4. saveState()
    By coderbob in forum Qt Programming
    Replies: 2
    Last Post: 27th March 2008, 11:50
  5. 4.2 saveState
    By merlvingian in forum Qt Programming
    Replies: 6
    Last Post: 1st November 2007, 15:24

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
  •  
Qt is a trademark of The Qt Company.