Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I retrieve a text description for a SQL field type?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonathan
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blex
      wrote on last edited by
      #2

      [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.


      Oleksiy Balabay

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jonathan
        wrote on last edited by
        #3

        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'...
        }

        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved