Results 1 to 3 of 3

Thread: How to save application settings which can be accessible in all forms?

  1. #1
    Join Date
    May 2011
    Posts
    16
    Thanks
    4
    Qt products
    Qt4

    Question How to save application settings which can be accessible in all forms?

    I'm creating an application which should have Options form (dialog) and in this form I want to save some parameters such as some folder path, some configuration numbers,etc.
    I want after saving the setting in the Options dialog, it saves it in the QSettings object and I'll be able to reload it when I need it.
    How can I do this? and because these settings are important to all of other dialogs, I want to know the most efficient way to save these settings and also load it easily and also it will be accessible to all dialogs.
    For example I have three forms:
    MainWindow
    Options
    SomeDialog

    folderPath1 = "c:/windows";
    folderPath2 = "d:/programs";
    size = 100;

    I want to load Settings (folderPath1 , folderPath2 , size) in the start of program using MainWindow. Then I would like to be able to edit these settings via Options dialog.
    In every point of program I would like to have access to these settings from SomeDialog.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to save application settings which can be accessible in all forms?

    QSettings, which you already identified, is a solution to this problem. What exactly is your difficulty?

  3. #3
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save application settings which can be accessible in all forms?

    All about logic. You can find help about QSettings

    you can write a function that loads your setting from an ini file. And call it from main form constructor.

    For a ini file;
    Qt Code:
    1. QString myinifilepath("myprogsettings.ini");
    2. QSettings myini(myinifilepath,QSettings::IniFormat);
    3. myini.beginGroup("Settings");
    4. if (myini.value("folderPath1").isValid())
    5. {
    6. ui->lineEdit1->setText(myini.value("folderPath1").toString());
    7. }
    8. .....
    9. .....
    10. ....
    11. myini.endGroup();
    To copy to clipboard, switch view to plain text mode 

    if you want to save your settings, you can call a save function, which event you want.

    Qt Code:
    1. myini.setValue("folderPath1",ui->lineEdit1->text());
    To copy to clipboard, switch view to plain text mode 

    please read the docs and write little prototype applications to learn.
    Last edited by kosasker; 16th July 2011 at 10:20.

Similar Threads

  1. Qt application settings in JSON
    By asvil in forum Qt-based Software
    Replies: 0
    Last Post: 5th March 2011, 21:35
  2. Replies: 0
    Last Post: 25th April 2010, 17:41
  3. Replies: 2
    Last Post: 2nd September 2009, 13:36
  4. Can we save & load the settings in GUI !
    By Krish in forum Newbie
    Replies: 6
    Last Post: 26th March 2008, 15:33
  5. Replies: 3
    Last Post: 31st March 2006, 18:38

Tags for this Thread

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.