how to read INI file and put into the array
-
Hi, i'm using Qt5.5 on my embedded linux computer.
It is my code hereI wanna put childkey and values into array.
Then compare them.
But i don't know how to do it.
Please Help! -
Hi, i'm using Qt5.5 on my embedded linux computer.
It is my code hereI wanna put childkey and values into array.
Then compare them.
But i don't know how to do it.
Please Help!@victor-wang Then put them into your array. What exactly is the problem?
-
@victor-wang Then put them into your array. What exactly is the problem?
-
@victor-wang You cannot use a string in switch - the error message actually says that.
You can only use integers in switch. You either use if ... else if... or you convert your string keys to integers/enum values. -
The error messaged is quite clear,
you're only allowed to use integers als switch key. Strings are not defined.
You'll have to do write that yourself or go the old-fashioned way of
if(){ }else if{ }else if{ } ...
Be warned however, comparing strings is not a fast process.
-
@victor-wang You cannot use a string in switch - the error message actually says that.
You can only use integers in switch. You either use if ... else if... or you convert your string keys to integers/enum values.@jsulm
Can you give me an example, i don't know how to do it.@J-Hilk
I can just only use if...else if...else for instead? -
@jsulm
Can you give me an example, i don't know how to do it.@J-Hilk
I can just only use if...else if...else for instead?@victor-wang How to use if? @J-Hilk already did. But here again:
if (childKey == "aaa") { ... } else if (childKey == "bbb") { ... } else if...
You can have an enum:
enum MyEnum { AAA, BBB, CCC, .... } // Ten a convert function MyEnum convert(QString key) { if (childKey == "aaa") { return AAA } else if (childKey == "bbb") { return BBB } else if... } // then your switch MyEnum key = convert(childKey); switch(key) { case AAA: break; case BBB: break ... }
-
@victor-wang How to use if? @J-Hilk already did. But here again:
if (childKey == "aaa") { ... } else if (childKey == "bbb") { ... } else if...
You can have an enum:
enum MyEnum { AAA, BBB, CCC, .... } // Ten a convert function MyEnum convert(QString key) { if (childKey == "aaa") { return AAA } else if (childKey == "bbb") { return BBB } else if... } // then your switch MyEnum key = convert(childKey); switch(key) { case AAA: break; case BBB: break ... }
Actually you dont have to go through the pain to define a convert-function
enum myEnum{/ AAA, BBB, CCC, ... }; Q_ENUM(myEnum) ... QString s = StringFromSettings; myEnum switchKey = static_cast<myEnum>(QMetaEnum::fromType<myEnum>().keyToValue(s.toLocal8Bit().data())); switch (switchKey){ case AAA:...break; ... default: .... break; }