Results 1 to 3 of 3

Thread: QMYSQL CHAR(1) mapped to QString

  1. #1
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    4

    Default QMYSQL CHAR(1) mapped to QString

    Hi! I have a MySQL table with a field defined as follows:

    type CHAR(1) NOT NULL DEFAULT 'Z'

    so it indicates whether each record is an input ('I'), an output ('O') or an unassigned value (that default 'Z' value). Maybe it could have more values in the future, so another letters would be used.

    Then, I have a C++ class IOConfig that has one Q_PROPERTY for each column in the table, so one instance of this class replicates one record of the table.

    So it has the following qproperty:

    Q_PROPERTY(QChar type READ type WRITE setType)

    The problem is when reading the record values through a QSqlRecord, it reads the "type" column as a QVariant::String so it doesn't coincide with the qproperty type, which is QVariant::Char.

    How could I solve this problem? I have been searching about this but found nothing relevant

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMYSQL CHAR(1) mapped to QString

    Why is that a problem? Can't you convert the type in getter and setter methods? A simple string[0] would do...

  3. The following user says thank you to wysota for this useful post:

    juannm (25th August 2008)

  4. #3
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    4

    Default Re: QMYSQL CHAR(1) mapped to QString

    well thats what I have done, everything in the QPROPERTY is a QString, except for the return type of the getter method, which is a QChar (that's because the rest of the code expects a QChar from the getter).

    Thanks anyway, I just wanted to know if there was another way of doing this thing.

Similar Threads

  1. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.