QSettings in c ++
in my .cpp, that I have a global integer starting at 1, whenever a function is running increases, but whenever the application is restarted, the # dates back to 1
int myNum; app::funcion() { QSettings settings; settings.setValue("MyCount", myNum++); }
Once the application is restared Qsettings will always be the last # until the function is called
what I have a problem with the value used in qSettings to continue counting rather than start over
any suggestion would be appreciated... using qml I know not how to load, but not c ++ where I use the value
To load it call this code once during initialization:
QVariant v = settings.value("MyCount"); if (!v.isNull()) myNum = v.toInt();
BTW, after call setValue, it is best to call settings.sync () so that the value is saved immediately.
Tags: BlackBerry Developers
Similar Questions
-
Fill out the strings of QSettings to ArrayDataModel
Hello
I want to read several QSettings strings and then fill in an ArrayDataModel.
So with this code, I've saved several channels in QSettings:
void ApplicationUI::saveDataInQSettings(QList
filepath) { QSettings settings; settings.beginWriteArray("filepaths"); for (int i = 0; i < filepath.size(); ++i) { settings.setArrayIndex(i); settings.setValue("filepath", filepath.at(i)); } settings.endArray(); } Now, I want to recover the QSettings channels as follows. I have a C++ function that fills the QSettings strings in a QList
: QList
ApplicationUI::fillQSettingsInQList() { QList filepaths; QSettings settings; int size = settings.beginReadArray("filepaths"); for (int i = 0; i < size; ++i) { settings.setArrayIndex(i); QString filepath; filepath = settings.value("filepath").toString(); filepaths.append(filepath); } settings.endArray(); return filepaths; } In my main.qml, I have a NavigationPane containing a container in which the ArrayDataModel is displayed.
I put the fillQSettingsInQList () - method in onCreationCompleted then I have the TI in QML when the application is open:
[...]NavigationPane { id: navigationPane onCreationCompleted: { Qt.app = app; var filepaths = app.fillQSettingsInQList(); }
But how can I now fill this strings in the ArrayDataModel?
Thanks for the replies. I have not used the track with a list of the QStrings. It is now much simpler.
I saved the ArrayDataModel strings in the QSettings in this way. First of all, I saved the channels how I'll put in the QSettings and different channels:
void ApplicationUI::saveDataModelInQSettings(bb::cascades::ArrayDataModel* model) { QSettings settings; settings.setValue("size", model->size()); for (int i = 0; i < model->size(); i++) { QVariantMap map = model->value(i).toMap(); settings.setValue("string_" + QString::number(i), map.value("string")); } }
And completely action to get the information back to the ArrayDataModel of the QSettings:
void ApplicationUI::fillQSettingsInDataModel(bb::cascades::ArrayDataModel* model) { QSettings settings; int size = settings.value("size", 0).toInt(); for (int i = 0; i < size; i++) { QString filepath = settings.value("string_" + QString::number(i), "String not found").toString(); model->append(filepath); } }
-
QSettings does not save my data
Hello
I tried to use QSettings to save certain settings for my application. I followed the example https://github.com/OpenSourceBB/Cascades-Samples/tree/master/QSettingsExample
but when I set new values for the settings app and close the application and reopen, I find the settings to the default values.
I even imported from QSettingsExample and run it on my device (Dev Alpha C with OS 10.2) but the same problem still there... no data is saved!
I wonder if something missing do QSettings save my data?
Thank you.
Thank you for the help... It was a bug in my code. the name of the object was sent with a Null value.
It's working now
-
Bool becomes QString when QSettings load
I met a problem when storing bool values in QSettings. It looks like a bug to me, but maybe I'm missing something?
I have this piece of code:
QSettings* settings = new QSettings(); qDebug() << "test setting is of type " << settings->value("test", false).typeName(); settings->setValue("test", true);qDebug() << "now test setting is of type " << settings->value("test", false).typeName();
In the first round, it will print
test parameter is of type bool
test setting is now of type bool
After that, it will print
test parameter is of type QString
test setting is now of type bool
In the first round, there is no stored definition, it takes the default value spent, but after the setting has been set once, it seems that it is stored as a QString and load as a QString on the application next run.
It is ruin a lot of things especially during the passage of the QVariant to QML.
My ugly solution right now is to make a
settings->setValue('test', settings->value('test', false).toBool())
the launch for each Boolean parameter that I have.
Anyone else seeing this?
This behavior is expected although not very intuitive.
QSettings stores type information in ini files. Always ask the specific type when accessing QSetting using the. toBool(), toInt(), toString() etc.I think it is more correct than the use of the workaround above because there is no guarantee on how QSettings stores data internally.
-
QMap in QSettings record and back to the rear
Hi again. I'm a bit of a desperate situation. I have a card flightList which is
QMap< QString, QMap
> flightListMap; Now, I need to store this card, then pull it out back when the application opens. I learned that QSettings serves for this purpose. What I've done below:
void ApplicationUI::saveSettings(QMap< QString, QMap
> flightListMap) { QSettings settings("myComp", "myApp"); settings.setValue("flightList", flightListMap);} But apparently, since I ask your help, it did not work (: error I got is:)
../src/applicationui.cpp:113:63: error: no matching function for call to 'QSettings::setValue(const char [19], QMap
>&)' I pray for your help.
Thank you!Well, I have work! I am writing down, so he could help other people as well because I was about to crash my laptop...
Things I should have done were;(1) write this on file .cpp Albums
typedef QMap< QString, QMap
> templatemap; Q_DECLARE_METATYPE(templatemap); (2) registration during execution so
qRegisterMetaType
> >("templatemap"); qRegisterMetaTypeStreamOperators > >("templatemap"); (3) Finally, successfully recover ():
QVariant qv = settings.value("flightList"); QMap< QString, QMap
> myMap = qv.value< QMap< QString, QMap > >(); Thanks for the information written in this link > http://developer.nokia.com/community/wiki/Saving_custom_structures_and_classes_to_QSettings
Hope that I might be able to help Canadians save time and who are stuck like me (:)
-
Update QSettings value directly
Hello
How to update QSettings, I'm directly when you're using QSettings save value when close app and then display value not directly.
I need this type when changing color title bar.
Thank you.
Here is another solution
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_ */
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") } } ] }
Use this workaround, your values will be updated as you change them.
It is a solution even as a Retranslate.onLocaleOrLanguageChanged.
This will help you
-
QSettings, components in other qml files
As is often the case with parameters, they are on another page in an application of everything. I use QSettings to similarly as the sample application starshipSettings and met the common problem that is the component, a button, etc., is in a file different qml and page in the application, its id and its properties are not recognized. How could this be overcome? I don't know that there is a simple solution that I could see it often to come.
If there are the superior means of persistent data, I'd be welcome to their learning.
Yes, if you take a look at the example parameters Starship ( https://github.com/blackberry/Cascades-Samples/tree/master/starshipsettings ) application, you will find the WarpDrive.qml been 'called' inside the main.qml, such as:
// Component with warp core image and slider with title and tooltip. WarpDrive { layout: StackLayout { leftPadding: 110 rightPadding: leftPadding } }
After that, you will find the box set also, such as:
CheckBox { id: uranuscanner text: "URANUS SCANNER" objectName: "uranuscanner" checked: _starshipApp.getValueFor(objectName, "yes") onCheckedChanged: { _starshipApp.saveValueFor(uranuscanner.objectName, checked) } }
So if you do a test on the WarpDrive.qml file, change the bellows of the label:
Label { text: "WARP DRIVE SPEED" textStyle { base: SystemDefaults.TextStyles.SmallText fontWeight: FontWeight.Bold color: Color.create ("#ff262626") } }
to something like:
Label { text: _starshipApp.getValueFor("uranuscanner", "") textStyle { base: SystemDefaults.TextStyles.SmallText fontWeight: FontWeight.Bold color: Color.create ("#ff262626") } }
just to read the value of the parameter in the text of the label.
-
Save data directly to the file .ini with QSettings
Hello
I want to directly record of QStrings in QSettings.
For testing purposes, I tried this.
void ApplicationUI::writeDataInQSettings() { QSettings settings("app/native/assets/data/filepaths.ini", QSettings::IniFormat); QString filepath = "filepath"; QVariant filename = "Filename"; settings.setValue(filepath, filename); settings.sync();}
This code is in a function in C++ that I call in qml directly when the application is open.
I have permission to open the file in the path. I checked this with open with a C++ stream.
But when I run the code, and then open the ini file is still empty. What I'm missing here?
QSettings settings("app/native/assets/data/filepaths.ini", QSettings::IniFormat);
file Assets is read-only. You can only write to the folder data (which is btw: automatically used with QSettings)
then try this
QSettings settings("data/filepaths.ini", QSettings::IniFormat);
-
Let say that my config file is empty. If I do that
QSettings settings; qDebug() << settings.value("test").isNull();
This returns True
So if I do
settings.setValue("Test", "");
The file to insert the value, Test =
so if I roll my first condition I download False.
It's me who does not understand something or the behavior is wrong?
Thank you
UPDATE: if I remove the = at the end of the Test, then it returns True.
Yes-"" is a valid value.
Stuart
-
QSettings allows to save the vector?
QSettings would be able to manage types of database?
For example, if I have a vector filled with instances of a client of the class that can include data such as Qt, whole, QDateTime, types etc. are at - it a way to save all these elements together at once. The reason is I have multiple instances of this class in a vector, therefore, I need all of the data in each class stored together as a 1, so it can be charged as 1.
QSettings would be able to handle this?
You store inside a QVariantList cities.
Your model may be something to the effect of
{
"CityCountryCollection":]
{
"cityName": "Ottawa",.
"countryName": "Canada".
},
{
"cityName": "Barcelona."
"countryName": "Spain".
}
]
}
Where {} represent QVariantMaps and [of] QVariantLists.
-
QSettings works only one way?
I created a color object:
Color myColor;
The implementation, I did this:
QSettings settings; // organization and app name set previously myColor = settings.value("mycolor").value
(); So far so good, but when I try to save the color:
settings.setValue("mycolor", myColor);
I get an error:
No function call corresponding to ' QSettings::setValue(const char[12], bb:cascades::Color&)
I've been reviewing the docs here (find "QVariant and Types of GUI" on the page)
https://developer.BlackBerry.com/Cascades/reference/qsettings.html
Any ideas?
QVariant is QtCore class and does not work with bb::cascades classes. Try to convert to QColor first (not tested):
bb::cascades::Color myColor; QColor color(myColor.red() * 255, myColor.green() * 255, myColor.blue() * 255, myColor.alpha() * 255); settings.setValue("color", color);
Reading requires a reverse conversion.
-
Registration of QTime in QSettings - problem
I'm trying to save certain settings. The code below demonstrates the correct alert with correct zoom box and updInter values.
QSettings settings("ASDF", "QAZWSX"); QTime pickerTime=root->property("pickerTime").toTime(); settings.beginGroup("AppSettings"); settings.setValue("zoom", root->property("zoom")); settings.setValue("updInter", pickerTime); alert(settings.value("updInter", "E4").toTime().toString()); settings.endGroup();
But code below (executed at the beginning of the app) shows the alert box correct with correct zoom and incorrect (00: 00:00) updInter values...
QSettings settings("ASDF", "QAZWSX"); settings.beginGroup("AppSettings"); alert(settings.value("zoom", "E3").toString()+" "+settings.value("updInter", "E4").toTime().toString()); settings.endGroup();
Thank you in advance for the help
Thanks, @tzander, but savings QTime wasn't mistake - the actual error was that, in some moments (probably onExit), application records QTime == '00:00:00.
So, I create simple ease condition:
if(root->property("pickerTime").toString().remove(0,11).compare("00:00:00")!=0){ settings.setValue("updInter", root->property("pickerTime")); }
QML file, I
property alias pickerTime: intervalPicker.value (...) DateTimePicker { id: intervalPicker mode: DateTimePickerMode.Timer value: dateFromTime("00:00:15") title: qsTr("Select") }
I think, it's very funny, DateTimePicker sometimes changes the value of time
-
How to use QSettings and TextField/TextArea with persistence stores a string?
I'm trying to store a string of data that the user enters in a TextField or TextArea. I want this channel to be persistent in memory whenever the user opens the application.
The Startshi sample application shows how this is done, but not with text in a TextField/TextArea.
The sample application shows:
Checkbox {}
ID: uranuscanner
text: "URANUS SCANNER.
objectName: "uranuscanner."
checked: _starshipApp.getValueFor (objectName, 'yes')
onCheckedChanged: {}
_starshipApp.saveValueFor (uranuscanner.objectName, verified)
}
}Data is retrieved with the bold line. Are there no property equivalent qml who does the same thing for a TextField/TextArea?
Thanks in advance,
RossIt's easy
I do it this way:
TextField { id: server text: odssettings.getValueFor("server/url","") hintText: qsTr("Server URL") + Retranslate.onLanguageChanged inputMode: TextFieldInputMode.Url textStyle { base: SystemDefaults.TextStyles.BodyText } onTextChanged: { odssettings.saveValueFor("server/url",server.text) } }
-
How to get the timestamp to install official application?
Is it possible to get the runtime the timestamp to install official application or datetime?
I not looking for third-party solutions or workaround, but just the bb: official package.It seems that it's not accessible, I looked at those:
BB::application
BB::Cascades:application
BB::ApplicationInfo
BB: PackageInfoAnd none has the information you're looking for.
Of course, it is quite easy to do it yourself with QSettings:
QSettings settings;
If (! settings.contains ("installDate")) {}
settings.setValue ("installDate", QDateTime::currentDateTime());)
} -
Getting google access_token
I had problems with the way to access the Google APIs, I was able to connect to Google, which otaining the authorization code.
However, the way Exchange code for the access token and refresh for the tokens that the problem, Google docs, only they provide an example of Javascript, but I dug and here is what I got:QUrl postUrl = QUrl("https://accounts.google.com/o/oauth2/token"); QNetworkRequest request(postUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrl params; // the auth code has been saved as code to declared QSettings settings params.addQueryItem("code=", settings->value("key").value
().append(" ")); params.addQueryItem("client_id=", ""); params.addQueryItem("client_secret=", " "); params.addQueryItem("redirect_uri=", "urn:ietf:wg:oauth:2.0:oob&"); params.addQueryItem("grant_type=", "authorization_code"); QNetworkReply* reply = m_networkmanager::post(request, params.encodedQuery()); bool ok = connect(reply, SIGNAL(finished()), this, SLOT(checkReply())); Q_ASSERT(ok); Q_UNUSED(ok); the answer I get is 'Bad Request'.
Please what am I doing wrong?.
How I put it right?.OAuth2 is complicated and poorly documented. You're doing C++? I have a class C++ OAuth2 library I wrote for my support application that manages Google OAuth by encapsulating the functioinal but clumsy OAuthQt library. All sites don't OAuth2 slightly differently and my library has been designed to be extensible to any variation that I needed in the future. Currently it handles only Google and Bitly, but I intend to develop many popular services and eventually publish under a Creative Commons license. I'm not willing to share the source code, but if you do things in C++ (or could do this way), I'd build you libraries arm and i86 and supply you with the header files you would use.
I am very careful when writing to my class for the Google libraries and Bitly classes both have the syntax of fully functional Builder so you can create and configure the OAuth with a single statement. Because I'm not ready to release this publicly I do have documentation so you should discuss with me to understand.
I must warn you that, even with a powerful helper like mine, OAuth2 class is quite complicated.
Maybe you are looking for
-
How can I access my library songs with someone's computer?
I sold my computer and don't think much about music on my phone. Well, I had to replace my phone, and I noticed that more than 500 songs, that I had on my music had disappeared. So I used the computer of my father who has installed iTune. I thought
-
error: could not write the destination file (1 003)
I am trying to export 40 photos of Photos. I just installed OX El Capitan. Only 13 of them get downloadable. For the rest, I get this message: error: could not write the destination file (1 003) I tried to manually fix the library but still does n
-
Acer Aspire E1 - 572G - problem after updating driver AMD
Hi guys! After the upgrade to the latest driver (14.12) for my gpu M265 R7, I find suddenly meeting me a problem quite stupid. Try to close my laptop, to say that the action is not completely filled. Screen stops, but other lights and stuff while rem
-
Process / task manager has a svchost.exe thatreally slows down and sometimes crashes my computer. Windows XP Media Center Edition with SP3. Is there any solution for this?
-
to try to correct the time zone schedule probs w/xp
I'm trying my timezone and it won't work, or if it's hard to find exactly the right download. I live in the area (Florida) Eastern time and my clock is off. as now, the actual time is 15:11 and my comp says 02:49. How can I fix? {Furthermore, I'm not