Results 1 to 4 of 4

Thread: Convery QByteArray to QVariantMap

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Exclamation Convery QByteArray to QVariantMap

    Hello All,,


    I have converted the QVariantMap to QByteArray via:
    Qt Code:
    1. QByteArray parameters;
    2. foreach( QVariant variant, values )
    3. parameters.append( variant.toChar() );
    To copy to clipboard, switch view to plain text mode 

    But i want to convert it back in QVariantMap.

    Any idea about converting QByteArray to QVariantMap

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Convery QByteArray to QVariantMap

    You can't recover the original QVariantMap... you have thrown away the QString keys from the map, and any QVariant value that was not convertable to QChar, and the original type (char, int or unit) of the QVariants that could be converted to char.

    You probably should consider using QDataStream to serialise/deserialise into a buffer.

  3. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Convery QByteArray to QVariantMap

    Works for me:
    I USE
    Qt Code:
    1. QByteArray parameters;
    2. QDataStream *stream = new QDataStream(&parameters, QIODevice::WriteOnly);
    3.  
    4. (*stream) << values;
    5. delete stream;
    6. stream = NULL;
    To copy to clipboard, switch view to plain text mode 
    Last edited by karankumar1609; 29th May 2013 at 13:54.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Convery QByteArray to QVariantMap

    This will only work if you used QDataStream to serialise the QVariantMap in the first place.

    There's no need to allocate the QDataStream on the heap at line 2. The syntax at line 4 is simplified, and lines 5 and 6 become unnecessary.

  5. The following user says thank you to ChrisW67 for this useful post:

    karankumar1609 (31st May 2013)

Similar Threads

  1. Traversing QVariantMap
    By ggdev001 in forum Newbie
    Replies: 9
    Last Post: 7th February 2013, 18:07
  2. Replies: 0
    Last Post: 10th December 2011, 12:17
  3. Replies: 0
    Last Post: 16th May 2010, 18:53
  4. Replies: 9
    Last Post: 25th July 2009, 14:27
  5. QVariant, QVariantMap, and QFileInfoList
    By themolecule in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 08:00

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.