Solved enum QVariant::Type is obsolete?
-
- I need to determine the types of the columns returned from a
QSqlQuery
. - I can access the column definitions via
QSqlQuery::record()::field(int)
. This returns aQSqlField
. - http://doc.qt.io/qt-5/qsqlfield.html#type gives me
QVariant::Type QSqlField::type() const
. - The return type of
QVariant::Type
is documented at http://doc.qt.io/qt-5/qvariant-obsolete.html#Type-enum under title "Obsolete Members for QVariant"
If it is obsolete, how come
QSqlField::type()
returns it? What should I be using instead to achieve this? - I need to determine the types of the columns returned from a
-
@JonB said in enum QVariant::Type is obsolete?:
What should I be using instead to achieve this?
There's some info at the documentation for QVariant::type().
QVariant::Type
has been superseded byQMetaType::Type
.The integral values of the two enums are interchangeable, so you can safely reinterpret the return value of
QSqlField::type()
as aQMetaType::Type
. You can also passQMetaType::Type
values intoQSqlField::setType()
.If it is obsolete, how come
QSqlField::type()
returns it?To maintain backwards-compatibility.
I'd imagine that in Qt 6, all instances of
QVariant::Type
will be fully replaced byQMetaType::Type
. -
This post is deleted! -
@JKSH
Thanks for that. I did not come across that link, if you follow the links through the manual as I said I did you don't hit http://doc.qt.io/qt-5/qvariant.html#type. I'm good to go on that.Are you happy with the way I'm saying I determine the "type" for a column returned from the database? I need to know that for arbitrary formatting etc. rules, e.g. suitable column alignment in a table.
-
This post is deleted! -
@JonB said in enum QVariant::Type is obsolete?:
@JKSH
Thanks for that. I did not come across that link, if you follow the links through the manual as I said I did you don't hit http://doc.qt.io/qt-5/qvariant.html#type. I'm good to go on that.You're welcome :) Looks like a bug/oversight in the documentation generator: https://bugreports.qt.io/browse/QTBUG-68327
Are you happy with the way I'm saying I determine the "type" for a column returned from the database? I need to know that for arbitrary formatting etc. rules, e.g. suitable column alignment in a table.
Yes, I think that's exactly how the designers of
QSqlField
intended it to be used.