View Full Version : Save enums in QSettings
redhat
20th January 2009, 11:15
Hi!
How I Can Save enums in QSettings???
And
I Have A Form With 4 Child Window
How I Can Save All Child Windows Settings Such as (size, pos, ...)???
Thanks.
spirit
20th January 2009, 11:30
Hi!
How I Can Save enums in QSettings???
you can cast enum value to QString and then write it using QSettings.
And
I Have A Form With 4 Child Window
How I Can Save All Child Windows Settings Such as (size, pos, ...)???
Thanks.
there is method only for QMainWindow
QByteArray QMainWindow::saveState ( int version = 0 ) const
in anohter case you need to do this manually.
redhat
20th January 2009, 12:07
Thanks for Your Response.
How I can cast a enum to QString???
spirit
20th January 2009, 12:19
you can do this using this method
QString::number
Returns a string equivalent of the number n according to the specified base.
or can do this
enum MyEnum {MyValue, ....};
...
QSettings settings("test.ini", QSettings::IniFormat);
settings.setValue("MyEnumValue", MyValue);
...
in result you'll get in ini-file
[General]
MyEnumValue=0
NoRulez
22nd January 2009, 11:22
You could also make it as follows:
enum MyEnum {MyValue...};
Q_ENUMS(MyEnum);
.
.
.
QString enum2Str(MyEnum value, const QString &enumName = "MyEnum") {
const QMetaObject &mo = SetupExporter::staticMetaObject;
int index = mo.indexOfEnumerator(enumName.toLatin1().constData ());
QMetaEnum metaEnum = mo.enumerator(index);
return QString(metaEnum.valueToKey(value));
}
.
.
.
QSettings settings("test.ini", QSettings::IniFormat);
settings.setValue(enum2Str(MyValue), MyValue);
Regards
NoRulez
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.