Thanks, but if it were only that simple...
I am porting Windows legacy code to Linux.
It's doable but a lot of work.
I was hoping that QT will is able to save the strings with quotes "" thus allowing it to read the value types correctly.
Thanks, but if it were only that simple...
I am porting Windows legacy code to Linux.
It's doable but a lot of work.
I was hoping that QT will is able to save the strings with quotes "" thus allowing it to read the value types correctly.
Last edited by yaronkle; 14th October 2013 at 08:28.
How does that matter?I am porting Windows legacy code to Linux.
Do mean to say the INI file is created using legacy APIs, and now you want to read using Qt APIs.
Why do you want know the types from INI file, you are supposed to know them upfront.I was hoping that QT will is able to save the strings with quotes "" thus allowing it to read the value types correctly
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
OK, let me explain.
I am porting Windows code that calls RegQueryValueEx (for example, there are other API's).
RegQueryValueEx returns the correct type to the user, since that type is written correctly in Windows Registry (also in QSettings as long as you run it without stopping the process).
I have written a Linux implementation of RegQueryValueEx.
I can modify all the calls to RegQueryValueEx (which is a hassle).
Because this is a multiplatform project, I can't guarantee that another developer won't call RegQueryValueEx and rely on it to return the correct type.
Don't mix up APIs. Either stick to Qt APIs on all platforms or use your custom (or legacy) on all platform.
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
So if I understand correctly you are not actually creating a Qt API for something but you are backing a compatibility shim of sorts by Qt code, right?
And you shim function has to return a typed value or at least a type on request?
While that sounds very painful to maintain long term, you probably have reasons not to do a clean port.
As far as I can see you have to options:
1) use a backend that contains the type information just like the original API's backend does
2) use a type-less backend and try to find the closest type by trying potental conversion
Cheers,
_
That is correct for both questions!
What is a backend?
Are you referring to QSettings::SetIniCodec?
I have an idea, I have seen QT add quotes at one time to. I think it was when I played with QSringList.
Thinking of storing strings as QStringList of length 0. QVariant::type() will probably return the correct value.
I have a working solution which was simpler than expected.
When writing string values to the INI file, I append "\"STRING" to the string
When reading generic values. If the QVariant is a string without the above prefix I assume it's an int.
Works like a charm.
Many thanks to all of you!
Last edited by yaronkle; 15th October 2013 at 09:31.
Bookmarks