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. Consistency between null QJsonValue and QVariant

Consistency between null QJsonValue and QVariant

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvariantjson
5 Posts 3 Posters 587 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.
  • M Offline
    M Offline
    Moia
    wrote on last edited by Moia
    #1

    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
    
    JonBJ 1 Reply Last reply
    0
    • M 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
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moia
        wrote on last edited by
        #3

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

        JonBJ 1 Reply Last reply
        0
        • M Moia

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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
          1
          • B Offline
            B Offline
            Bonnie
            wrote on last edited by Bonnie
            #5

            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
            1

            • Login

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