QVariant for int/double members that could be "Null" ?
I am porting a few methods/classes from C/++ and some have int/double members that could be "Null." I assigned them a known invalid value in the old code to indicate they are "Null."
I am wondering if in Qt if it would be a better practice to use a QVariant in these cases? Is there any "best practice" for handling these types of properties? The data will be read from a database, edited by the user in a GUI form, displayed on reports and various file exports.
Thanks for any suggestions,
Common pratice for i is to use known invalid values as you did, but as from my POV it is slightly ugly and error-possible. Also there are sometimes custom classes-wrappers, but it removes POD attribute from variable. Qvariant is a standartized and common for big number of types solution and handles a lot of non-usual states.
QVariant is a good solution for you I think.
Thanks Denis. I gave it some more thought and decided to go the QVariant way.