Results 1 to 10 of 10

Thread: QWidget Settings advanced idea

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QWidget Settings advanced idea

    Hi to all!

    I got an idea how to save settings for a widget, but I do no know how to code it. Here is my problem:

    In my app I have several widgets (mostly QWidget) - settings pages under main settings window (also derived from QWidget). Every settings page has QLabels, QTextEdits, QComboboxes, etc ... Now, when I click save, the save slot connected to signal clicked must get contens of all textedits and other value input widgets and save them in a object, which class is subclassed from QSettings. At the end, this app must notify sister parent application that new settings has been apllied to ini file and client must reeread settings without terminating and reruning it. Is this possible?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget Settings advanced idea

    Yes, it's possible.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QWidget Settings advanced idea

    How? I do not want to write the code for me, but I just want some guidelines ...
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget Settings advanced idea

    I'd recommend taking a look at functions like QWidget::saveGeometry() and QMainWindow::saveState() and their corresponding restore() counterparts. I suggest you implement similar interface for your settings page. This way the main window doesn't have to do anything else but simply call saveState() and restoreState() for every settings page. The settings page itself would be responsible for saving and restoring anything it needs.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QWidget Settings advanced idea

    But I do not need to save geometry of windows, but contens of QTextEdits inside settings page, ie, the contens (mainly text() method) of child objects (QTextEdit, QLabel, ...) of settings page. I've made a QSettings subclassed class named CAppSettings, which header is as follows:
    Qt Code:
    1. #ifndef CAPPLICATIONSETTINGS_H_
    2. #define CAPPLICATIONSETTINGS_H_
    3.  
    4. // qt includes
    5. #include <QSettings>
    6. #include <QList>
    7. #include <QApplication>
    8. #include <QObject>
    9. #include <QVariant>
    10.  
    11. // custom includes
    12. #include "globals.h"
    13.  
    14. typedef struct
    15. {
    16. QString strHub;
    17. QString strKey;
    18. QVariant varValue;
    19. } settingsType;
    20.  
    21. /*!
    22.  * class responsible for whole EROSystem Settings
    23.  */
    24. class CApplicationSettings : public QSettings
    25. {
    26. Q_OBJECT
    27.  
    28. public:
    29. CApplicationSettings(const QString &strFileName=strIniFileName,
    30. Format format=IniFormat,
    31. QObject *pParent=0);
    32. ~CApplicationSettings();
    33.  
    34. private slots:
    35. void saveSettings(); // method for saving settings
    36. void loadSettings(); // method for loading settings
    37.  
    38. private:
    39. QList<settingsType> m_SettingsValues;
    40. };
    41.  
    42. #endif /*CAPPLICATIONSETTINGS_H_*/
    To copy to clipboard, switch view to plain text mode 

    Now, how do I extract control widget (QLineEdit, QLabel) pointer from pParent? This is my first question. And then, how do I notify about new settings client application, whose flowchart depends on settings from:
    Qt Code:
    1. private:
    2. QList<settingsType> m_SettingsValues;
    To copy to clipboard, switch view to plain text mode 
    Last edited by MarkoSan; 15th March 2008 at 18:52.
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget Settings advanced idea

    I didn't say anything about saving geometry. I just recommended implementing a similar interface to your settings pages.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Red face Re: QWidget Settings advanced idea

    Ok, jpn and all other kind experts, I am back to this section of my project. I've setup an INI file and it is created upon constructor call like it should. Now, I do not know how to extract all key names for a key. For example, this is example ini file:
    Qt Code:
    1. [GeometrySettings]
    2. x1=100
    3. x2=100
    4. y1=200
    5. y2=200
    6. background=blue
    To copy to clipboard, switch view to plain text mode 

    Now, I have been reading QSettings docs for a while, but I simply do not know how to extract strings x1, x2, y1, y2 (keys) from GeometrySettings hub. For example, I need a call that will for example call:
    Qt Code:
    1. QStringList strKeys=QSettings::keys(QString("GeometrySettings"));
    To copy to clipboard, switch view to plain text mode 
    return strings "x1', "x2", "y1", "y2" string in string list. I cannot find that function. So, does anyone has idea how to implement it. The problem is that I write uniform QSettings subclassed class that will be used by all applications in my software project and this class does not know how many and which keys are under some settings hub. Please help!
    Qt 5.3 Opensource & Creator 3.1.2

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget Settings advanced idea

    Qt Code:
    1. settings.beginGroup("GeometrySettings");
    2. qDebug() << settings.childKeys();
    3. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    MarkoSan (25th March 2008)

  10. #9
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWidget Settings advanced idea

    Hi, if you have lots of widgets that have similar settings, maybe consider some more automatic mechanism.
    We have overridden spinboxes and splitters in our application that generates keys using kind of path from mainwindow to given widget, and saves/restores own states on show/hide.
    we had to write code for view hundreds of widgets once instead of view hundreds.
    You could add such mechanism to textedits, labels and combos and eventually turn it on/off for right widgets - it was lot less work to do in my case.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  11. The following user says thank you to mchara for this useful post:

    MarkoSan (27th March 2008)

  12. #10
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QWidget Settings advanced idea

    Well, I've developed separate class that handles settings and now it is used heavely. Thanks for hints ...
    Qt 5.3 Opensource & Creator 3.1.2

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.