Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 38
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI
Accepted Solution

Update QSettings Value Directly

[ Edited ]

Hi,

 

How to update QSettings directly i'm when using QSettings save value when close app and then show value not directly.

 

I need this like for when change color titlebar.

 

 

Thanks.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Update QSettings Value Directly

Struggling to understand what you are asking.

 

Are you asking how to update a setting when the app is closed?

 

If so you would need to go headless for that.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Update QSettings Value Directly

class YouSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(QString titleBarColor READ titleBarColor WRITE setTitleBarColor NOTIFY dataChanged)
    public:
        .............

    //You setters/getters for titleBarColor
    inline QString titleBarColor() const { return _titlebarColor; }
    inline void setTitleBarColor(const QString &value){
        if (_titleBarColor != value){
            _titleBarColor = value;
            emit dataChanged();
        }
    }

private:
    QString _titleBarColor;

};

titleBarcolor is updated right after you change the value. 

 

More info about property system

http://qt-project.org/doc/qt-4.8/properties.html



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
New Developer
Posts: 38
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Re: Update QSettings Value Directly

@BBSJdev

 

No no, i mean update value Qsetting without close app.

 


 

 

@Benecore

 

Thanks this what i mean.

 

But how to do this with all object like when do this:

 

QString ApplicationUI::getValueFor(const QString &objectName, const QString &defaultValue)
{
    QSettings settings;
    if (settings.value(objectName).isNull()) {
        return defaultValue;
    }
    return settings.value(objectName).toString();
}

void ApplicationUI::saveValueFor(const QString &objectName, const QString &inputValue)
{
    QSettings settings;
    settings.setValue(objectName, QVariant(inputValue));
}

 

 

 

Developer
Posts: 16,643
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Update QSettings Value Directly

you don't have to close the app to save settings.

I find it difficult to understand your questions. What do you mean with "how to do this wil all object"?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Update QSettings Value Directly

[ Edited ]

 New Developer The only way to do this with your settings class which is non-based on Q_PROPERTY system, is create a signal and emit-ing it when you change value.

Then in QML you need to update all values manually so you need to call getValueFor function when the signal is emitted

 

PS: I'm using settings class like an example which i have given you above in all of my apps. Because i need Q_PROPERTY system and update all values in whole app right after i change it. So i recommend this option to you

It's more code, but much better solution :smileywink:



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Update QSettings Value Directly

[ Edited ]

Here is another solution :smileywink:

 

applicationui.hpp

class ApplicationUI : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString onDataChanged READ onDataChanged NOTIFY dataChanged)
public:
    ApplicationUI();
    virtual ~ApplicationUI() {}

    Q_INVOKABLE
    inline QString getValueFor(const QString &objectName, const QString &defaultValue)
    {
        QSettings settings;
        if (settings.value(objectName).isNull()) {
            return defaultValue;
        }
        return settings.value(objectName).toString();
    }
    Q_INVOKABLE
    inline void saveValueFor(const QString &objectName, const QString &inputValue)
    {
        QSettings settings;
        settings.setValue(objectName, QVariant(inputValue));
        emit dataChanged();
    }

signals:
    void dataChanged();

private slots:
    QString onDataChanged() const { return QString(); }
    void onSystemLanguageChanged();
private:
    QTranslator* m_pTranslator;
    bb::cascades::LocaleHandler* m_pLocaleHandler;
};

#endif /* ApplicationUI_HPP_ */

 And then on QML use it like this

import bb.cascades 1.2

Page {
    Container {
        Label {
            // Localized text with the dynamic translation and locale updates support
            text: app.getValueFor("title", "Hello World") + app.onDataChanged
            textStyle.base: SystemDefaults.TextStyles.BigText
        }
    }
    
    actions: [
        ActionItem {
            ActionBar.placement: ActionBarPlacement.OnBar
            title: "Change value"
            onTriggered: {
                app.saveValueFor("title", "Change value")
            }
        }
    ]
}

Using this workaround, your values will be updated right after you change them. 

 

This is same solution like a Retranslate.onLocaleOrLanguageChanged .

 

This will help you :Punk:



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
New Developer
Posts: 38
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Re: Update QSettings Value Directly

@simon_hain

I mean update settings without close app to change like use title bar color.

"how to do this wil all object" What I mean is when you use more than one object in QML is updated as well.

 


 

 

@Benecore

 

Yeah good and run with all object.

 

Thank you very much.