PDA

View Full Version : [SOLVED] QVariant and user structures



pdoria
31st July 2009, 13:46
Hi,

I have this structure:


typedef struct
{
uint32 status_change_id;
boolean result_code;
uint8 reserved[3]; /* Set to 0 */
} driver_id_receipt_data_type;

I'm trying to:

driver_id_receipt_data_type receipt;
QVariant packet;
// after filling the structure's members with data...
packet.setValue(receipt); // ERROR Line


Could somebody please tell me what's wrong with this code?

I have this function:

void send_FleetManagementPacket(QDataStream & dstream, QVariant packet);
which serves to send to arbitrary data to a stream.

I was hoping to pass the data through a QVariant thus eliminating the need for a ton of orverloaded functions...

TIA,
Pedro

pdoria
31st July 2009, 14:26
Looking at the docs I've found the

Q_DECLARE_METATYPE(type);

So obviously I've tried it immediately ... :p


typedef struct
{
quint32 status_change_id; /* timestamp of status change */
bool result_code;
quint8 reserved[3]; /* Set to 0 */
} driver_status_receipt_data_type;
Q_DECLARE_METATYPE(driver_id_receipt_data_type);

No joy... :(

This is what the compiler throws:
error: expected constructor, destructor, or type conversion before ';' token

TIA for any pointers!
Pedro.

shentian
31st July 2009, 14:44
The error message probably occurs because the compiler doesn't know the macro Q_DECLARE_METATYPE. Don't forget to include <QMetaType>.

By the way, use the correct class name in the macro:



Q_DECLARE_METATYPE(driver_status_receipt_data_type );
// Q_DECLARE_METATYPE(driver_id_receipt_data_type);

pdoria
31st July 2009, 14:50
Txs Shentian!

the #include <QMetaType> was missing! :o
It's always the little things like this that bites you in a** ! :D

BR,
Pedro