Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVariant::fromValue() throws error
Forum Updated to NodeBB v4.3 + New Features

QVariant::fromValue() throws error

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.1k Views 1 Watching
  • 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.
  • X Offline
    X Offline
    xchg.ca
    wrote on last edited by
    #1

    Hi guys,

    I cannot wrap my mind why QVariant::fromValue("test");
    gives me an error:

    C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\include\QtCore\qmetatype.h:642: error: C2338: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system

    using QT 5.0.2 and QRCreator 2.7.0

    and what should I do to create QVariant from const char*

    1 Reply Last reply
    0
    • francescmmF Offline
      francescmmF Offline
      francescmm
      wrote on last edited by
      #2

      As you can see in "Documentation":http://qt-project.org/doc/qt-5.0/qtcore/qvariant.html#setValue , the const char * is not a valid value. For this reason a compilation error occurs.

      You must only send the value with QVariant("test").

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xchg.ca
        wrote on last edited by
        #3

        [quote author="francescmm" date="1373040271"]
        You must only send the value with QVariant("test").[/quote]

        I've tried that already and I got:
        error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant'

        PS. I'm noob in QT, so expect some strange questions.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Could you show the code where you are trying to do that ?

          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
          • X Offline
            X Offline
            xchg.ca
            wrote on last edited by
            #5

            My code is irrelevant, this suppose to be one liner anyways
            In my case I've done this:

            QVariant::fromValue(QStringLiteral("test"));

            Seems to be working.

            Thank you

            1 Reply Last reply
            0
            • francescmmF Offline
              francescmmF Offline
              francescmm
              wrote on last edited by
              #6

              Edit by bad reading... u.u''

              Sorry!

              1 Reply Last reply
              0

              • Login

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