How can I retrieve a text description for a SQL field type?



  • I'm using QSqlRecord.field() to get a QSqlField object.

    From the QSqlField object I can get the name of the field using QSqlField.name().

    I can also use QSqlField.value() to return an enumeration which identifies the type (eg String, Date, Int, etc).

    However I can't see how to use this enumeration to return a string representation of the type.



  • [quote author="Jonathan" date="1290118885"]I can also use QSqlField.value() to return an enumeration which identifies the type (eg String, Date, Int, etc).[/quote]

    Is it really QSqlField.value()? Probably, you are talking about QSqlField.type().

    QSqlField::type() returns QVariant::Type. Maybe

    @const char * QVariant::typeName () const@

    will help you.



  • I did indeed mean QSqlField.type().

    Thanks for the pointer.

    The following code does the trick:
    @
    QSqlRecord record = ...
    for (int i=0; i<record.count(); i++)
    {
    QSqlField field = record.field(i);
    QString fieldName = field.name();
    QString fieldType = QVariant::typeToName(field.type());
    ...do something with 'fieldName' and 'fieldType'...
    }

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.