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
Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Qsettings not working any more

Hello,

I recently got back into coding for the BB10. I am trying to get an existing application I have working on my Q10 device, everything is working great except for QSettings, its not restoring the settings. The same configuration works on everything else my Qt app works on including windows, linux, android, symbian, playbook, etc etc...

I set up the Qsettings in main.cpp as per usual..

Is anybody else having trouble with this?

Attached is a small example.

Thanks for any help provided!

Cheers,

Jon

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

Re: Qsettings not working any more

what kind of jumps up is that you use setPath on the settings in your on_textEdited_textChanged() method, but not on your MainWindow class.
In the API sample they use organization name and app name to construct the settings or call QCoreApplication::setOrganizationName etc, maybe that makes a difference on bb10?

I would suggest to try a few options, start with the approach recommended in the API and see if it works.
----------------------------------------------------------
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: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: Qsettings not working any more

Hi Simon,

I did set it up as sugested in the documentation, its done in main.cpp and then applies accross the entire application, then you dont have to set the path each time you create the settings object.

From the docs here: http://qt-project.org/doc/qt-4.8/qsettings.html

If you use QSettings from many places in your application, you might want to specify the organization name and the application name using QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName(), and then use the default QSettings constructor:

     QCoreApplication::setOrganizationName("MySoft");
     QCoreApplication::setOrganizationDomain("mysoft.com");
     QCoreApplication::setApplicationName("Star Runner");
     ...
     QSettings settings;

 And in my main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setOrganizationName("HeronBoy");
    a.setOrganizationDomain("theHerons.ca");
    a.setApplicationName("Bio Logger");
    MainWindow w;
    w.show();

    return a.exec();
}

 This has worked for years accross multiple platforms including the playbook...

Cheers,

Jon

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Qsettings not working any more

forget all your QCoreApplication::set....  code - you only need

 

QSettings settings;

 

The QSettings file is automatically saved here:

 

/data/settings/---your vendor name---/---your-app-name.conf

 

 

 

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: Qsettings not working any more

Thanks, that works.
Too bad the standard way doesn't work any more, just more code to alter for BB10.
I will file a bug.
Cheers,
Jon
Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: Qsettings not working any more

Spoke too soon...  Seems Qsettings is broken on bb10.

While you can store one thing at a time, using groups does not work, only one variable will get stored in the group and then the rest will get ignored.

Example:

    settings.beginGroup("tankVol");
    settings.setValue("ori", ui->cbTankVol->currentIndex());
    settings.setValue("inch", ui->cbInch->currentIndex());
    settings.setValue("height", ui->dblSpinHight->value());
    settings.setValue("dia", ui->dblSpinDiameter->value());
    settings.setValue("circ", ui->cbCirc->currentIndex());
    settings.setValue("length", ui->dblSpinLength->value());
    settings.setValue("cone", ui->dblSpinConeDepth->value());
    settings.setValue("result", ui->lblTankVolume->text());
    settings.endGroup();

 Only one variable will be stored, the highest variable up in the list will be the only one stored while the rest will be ignored...

As I stated previously, this same code works flawlessly on all other platforms supported by Qt...

Cheers,

Jon

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Qsettings not working any more

never used groups this way

 

to group my settings hierarchical I'm using keys like

 

groupa/propertyone

 

to store more complex things I'm using JSON

 

and for me as a cascades developer (not having to support other Qt apps) of course it's really easy only "to use" QSettings and out-of-the-box the settings are stored at the right place

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: Qsettings not working any more

Thats how groups are used, see the documentation.

Bug filed here:

https://bugreports.qt-project.org/browse/QTBUG-37173

Cheers,

Jon