Results 1 to 2 of 2

Thread: QSettings mysteries

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSettings mysteries

    I have simply

    Qt Code:
    1. void mainWindow::readSettings()
    2. {
    3.  
    4. QSettings settings("GDEM","Rubic 1.0");
    5. settings.beginGroup("mainWindow");
    6. resize(settings.value("size",QSize(400,400)).toSize());
    7. move(settings.value("pos",QPoint(200,200)).toPoint());
    8. if (settings.contains("splitterSize"))
    9. splitterSettings = (settings.value("splitterSize").toByteArray());
    10. #ifdef DEBUG
    11. qDebug()<<"createConnection, database loaded ok:"<<databaseName<<settings.value("pos").toString().isEmpty()
    12. <<settings.contains("size");
    13. #endif
    14. settings.endGroup();
    15.  
    16. settings.beginGroup("database");
    17. if (settings.contains("databaseName") && (!settings.value("databaseName").toString().isEmpty())) {
    18. databaseName = settings.value("databaseName").toString();
    19. currentDatabase = databaseName;
    20.  
    21. }
    22. else
    23. databaseName="rubric.db";
    24.  
    25.  
    26. settings.endGroup();
    27. #ifdef DEBUG
    28. qDebug()<<"settings loaded ok:"<<settings.value("size").toString();
    29. #endif
    30. settings.sync();
    31. }
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. void mainWindow::writeSettings()
    2. {
    3. QSettings settings("GDEM","Rubi 1.0");
    4. settings.beginGroup("mainWindow");
    5. settings.setValue("pos",pos());
    6. settings.setValue("size",size());
    7. settings.setValue("splitterSize",mainSplitter->saveState());
    8. settings.endGroup();
    9.  
    10. settings.beginGroup("database");
    11. settings.setValue("databaseName",currentDatabase);
    12. settings.endGroup();
    13. settings.sync();
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. void mainWindow::closeEvent(QCloseEvent *event)
    2. { writeSettings();
    3.  
    4. QSqlDatabase database = QSqlDatabase::database();
    5. QSqlDatabase::removeDatabase();
    6. event->accept();
    7. }
    To copy to clipboard, switch view to plain text mode 

    I checked the file Rubic 1.0
    Qt Code:
    1. [mainWindow]
    2. pos=@Point(200 200)
    3. size=@Size(400 400)
    4. splitterSize=@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x2\0\0\0^\0\0\0\xa1\x1\0\0\0\x6\x1\0\0\0\x2)
    5.  
    6. [database]
    7. databaseName=rubric.db
    To copy to clipboard, switch view to plain text mode 
    and if I resize the window the values accordingly change.
    But: if I re-run the application the values are not loaded.
    Why?

    I call readsettings in the constructor
    Last edited by jacek; 6th November 2008 at 22:11. Reason: wrapped too long line

  2. #2
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings mysteries

    Sorry,
    I mitaken the file name (readSettings and writeSettings)
    G

Similar Threads

  1. QSettings and closeEvent()
    By vito49 in forum Newbie
    Replies: 2
    Last Post: 13th October 2008, 16:18
  2. QSettings problem?
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2008, 21:14
  3. QSettings and QGLWidgets
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2008, 18:01
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21
  5. Using QSettings to populate a QComboBox
    By nbkhwjm in forum Newbie
    Replies: 16
    Last Post: 4th September 2007, 22:34

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.