Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Consistency between null QJsonValue and QVariant

    General and Desktop
    qvariant json
    3
    5
    183
    Loading More Posts
    • 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.
    • M
      Moia last edited by Moia

      Suppose to have QJsonValue with a null type and then convert it to QVariant. This QVariant converted has type std::nullptr_t. It's just me or does not exists a way to instantiate a QVariant which match that type?

      QJsonValue value{QJsonValue::Null};
      QVariant variant = value.toVariant();
      
      qDebug() << value << variant;     //  QJsonValue(null) QVariant(std::nullptr_t, (nullptr))
      qDebug()  << variant.isNull() << variant.isValid();     //  true true
      qDebug() << variant.type() << variant.typeName();       // QVariant::std::nullptr_t std::nullptr_t
      
      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Moia last edited by

        @Moia
        I don't understand: you have instantiated a QVariant with that type, via your QVariant variant = value.toVariant();?

        1 Reply Last reply Reply Quote 0
        • M
          Moia last edited by

          How can I create a QVariant with the same state Variant(std::nullptr_t, (nullptr)) ?

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Moia last edited by

            @Moia
            Like I said, there may be other ways, but you already have done just this with your:

            QJsonValue value{QJsonValue::Null};
            QVariant variant = value.toVariant();
            

            ?

            1 Reply Last reply Reply Quote 1
            • B
              Bonnie last edited by Bonnie

              Maybe @Moia want a method to get that QVariant without a QJsonValue?
              By looking into the source code of QJsonValue, you can see that value comes from

              QVariant::fromValue(nullptr)
              
              1 Reply Last reply Reply Quote 1
              • First post
                Last post