PDA

View Full Version : QMYSQL CHAR(1) mapped to QString



juannm
19th August 2008, 17:58
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 :(

wysota
25th August 2008, 07:43
Why is that a problem? Can't you convert the type in getter and setter methods? A simple string[0] would do...

juannm
25th August 2008, 11:18
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.