Results 1 to 3 of 3

Thread: Error conversion from QMap<QString, QVariantList> to QVariant

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error conversion from QMap<QString, QVariantList> to QVariant

    Hello!

    I've tried to convert QMap<QString, QVariantList> to QVariant, but I obtained compillation error:

    Qt Code:
    1. error: conversion from QMap<QString, QVariantList> to non-scalar type 'QVariant' requested
    To copy to clipboard, switch view to plain text mode 

    By the way, QMap<QString, QVariant> converts to QVariant fine.

    I've looked Qt documentation about QVariant, but didn't find anything about it.
    Possibly, the reason is that one container have another one into it.

    Could you explain this situation, please?


    Added after 29 minutes:


    Oh, sorry. Of course such type QMap<QString, QVariantList> is not listed in enum QVariant::Type (Only QMap<QString, QVariant>).

    But in Qt5 this enum is obsolete.
    Do anyone know, is it works in Qt5? (Unfortunatelly, I could not try it now.)
    Last edited by alexeyGL; 4th July 2013 at 12:57.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error conversion from QMap<QString, QVariantList> to QVariant

    QVariant can deal with any type that has certain properties such as being default constructible, copyable and assignable.

    For non-built-in types it is necessary to declare them to the Qt meta type system using Q_DECLARE_METATYPE

    Qt Code:
    1. Q_DECLARE_METATYPE(QMap<QString, QVariantList>);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error conversion from QMap<QString, QVariantList> to QVariant

    Thank you!

Similar Threads

  1. Replies: 3
    Last Post: 27th July 2012, 10:30
  2. Replies: 0
    Last Post: 20th April 2012, 17:16
  3. Enum To QString Conversion
    By yagabey in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2012, 15:28
  4. Replies: 4
    Last Post: 4th January 2011, 13:07
  5. How to add metatype support for QMap<int,QVariant>?
    By makinenh in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 17:15

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.