Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. <Resolved> Convert QHash <long long int, QList<long long int>> into a QVariant
QtWS25 Last Chance

<Resolved> Convert QHash <long long int, QList<long long int>> into a QVariant

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 6.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheIlliterate
    wrote on 13 Mar 2013, 01:18 last edited by
    #1

    Hello Guys:
    Another Conversion pain question

    I have QHash <long long int, QList<long long int> > object which I need to convert to a QVariant. But I am unable to do so. Kindly anyone can tell me what i need to be doing in this case.

    I really dont want to a use QHash <QString , QList <QVariant> > instead of QHash <long long int, QList<long long int> >

    Regards

    The Illiterate

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Mar 2013, 06:40 last edited by
      #2

      @
      // Setting:

      QVariant storage = QVariant::fromValue(yourHashObjectPointer);

      // Getting:
      QHash <long long, QList<long long> > result = storage.value<QHash <long long, QList<long long> > >();
      @

      (Z(:^

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TheIlliterate
        wrote on 13 Mar 2013, 22:22 last edited by
        #3

        Thanks Sierdzio, but that did not work for me. I was still getting compilation erros
        So I tried Registering my QHash type.

        @typedef QHash<long long int, QList<long long int>> HashMap;
        } /namespace custom/
        } /namespace my/
        Q_DECLARE_METATYPE( my::custom::HashMap );@

        but still gives me compilation errors:

        @usr/include/qt4/QtCore/qmetatype.h: In function 'void* qMetaTypeConstructHelper(const T*) [with T = QHash<long long int, QList<long long int> >]':
        usr/include/qt4/QtCore/qmetatype.h:196:25: instantiated from 'int qRegisterMetaType(const char*, T*) [with T = QHash<long long int, QList<long long int> >]'
        ../xxxxx/xxxxx/xxxxx.hpp:xx:1: instantiated from here
        usr/include/qt4/QtCore/qmetatype.h:141:22: error: invalid use of incomplete type 'struct QHash<long long int, QList<long long int> >'
        usr/include/qt4/QtCore/qdatastream.h:66:37: error: declaration of 'struct QHash<long long int, QList<long long int> >'
        usr/include/qt4/QtCore/qmetatype.h:142:43: error: invalid use of incomplete type 'struct QHash<long long int, QList<long long int> >'
        usr/include/qt4/QtCore/qdatastream.h:66:37: error: declaration of 'struct QHash<long long int, QList<long long int> >'
        usr/include/qt4/QtCore/qmetatype.h: In function 'void qMetaTypeDeleteHelper(T*) [with T = QHash<long long int, QList<long long int> >]':
        usr/include/qt4/QtCore/qmetatype.h:198:22: instantiated from 'int qRegisterMetaType(const char*, T*) [with T = QHash<long long int, QList<long long int> >]@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Mar 2013, 09:37 last edited by
          #4

          Hi,

          You might have forgotten to include QHash. Otherwise it the typedef/Q_DECLARE_METATYPE combo works well.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TheIlliterate
            wrote on 14 Mar 2013, 19:57 last edited by
            #5

            Thanks SGaist. You are right :) I wasted a lot of time assuming one of the many included header files must already contains include for QHash, but they did not :(

            Thanks a lot :)

            Regards
            The Illiterate

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 14 Mar 2013, 20:41 last edited by
              #6

              Qt headers use forward declaration to speed up compilation time. It's good practice to include everything that you declare. Avoiding module includes is also a good idea (so, no <QtCore> but <QString>).

              (Z(:^

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TheIlliterate
                wrote on 14 Mar 2013, 20:44 last edited by
                #7

                Thanks sierdzio for the valuable tip :)

                Regards
                The Illiterate

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 15 Mar 2013, 08:45 last edited by
                  #8

                  You're welcome !
                  Don't forget to set the thread's title to solved :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TheIlliterate
                    wrote on 15 Mar 2013, 15:37 last edited by
                    #9

                    Done! Thanks:)

                    1 Reply Last reply
                    0

                    1/9

                    13 Mar 2013, 01:18

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved