Results 1 to 4 of 4

Thread: [SOLVED] QVariant and user structures

  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question [SOLVED] QVariant and user structures

    Hi,

    I have this structure:

    Qt Code:
    1. typedef struct
    2. {
    3. uint32 status_change_id;
    4. boolean result_code;
    5. uint8 reserved[3]; /* Set to 0 */
    6. } driver_id_receipt_data_type;
    To copy to clipboard, switch view to plain text mode 

    I'm trying to:
    Qt Code:
    1. driver_id_receipt_data_type receipt;
    2. QVariant packet;
    3. // after filling the structure's members with data...
    4. packet.setValue(receipt); // ERROR Line
    To copy to clipboard, switch view to plain text mode 

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

    I have this function:
    Qt Code:
    1. void send_FleetManagementPacket(QDataStream & dstream, QVariant packet);
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by pdoria; 31st July 2009 at 14:51.

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QVariant and user structures

    Looking at the docs I've found the
    Qt Code:
    1. Q_DECLARE_METATYPE(type);
    To copy to clipboard, switch view to plain text mode 

    So obviously I've tried it immediately ...

    Qt Code:
    1. typedef struct
    2. {
    3. quint32 status_change_id; /* timestamp of status change */
    4. bool result_code;
    5. quint8 reserved[3]; /* Set to 0 */
    6. } driver_status_receipt_data_type;
    7. Q_DECLARE_METATYPE(driver_id_receipt_data_type);
    To copy to clipboard, switch view to plain text mode 

    No joy...

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

    TIA for any pointers!
    Pedro.

  3. #3
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QVariant and user structures

    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:

    Qt Code:
    1. Q_DECLARE_METATYPE(driver_status_receipt_data_type);
    2. // Q_DECLARE_METATYPE(driver_id_receipt_data_type);
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to shentian for this useful post:

    pdoria (31st July 2009)

  5. #4
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: QVariant and user structures

    Txs Shentian!

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

    BR,
    Pedro

Similar Threads

  1. attaching user data pointer to images in QTextEdit
    By Workeml in forum Qt Programming
    Replies: 0
    Last Post: 7th November 2008, 20:06

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.