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
Forum Updated to NodeBB v4.3 + New Features

Consistency between null QJsonValue and QVariant

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvariantjson
5 Posts 3 Posters 628 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.
  • M Offline
    M Offline
    Moia
    wrote on 28 May 2020, 09:11 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
    
    J 1 Reply Last reply 28 May 2020, 09:17
    0
    • M Moia
      28 May 2020, 09:11

      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
      
      J Offline
      J Offline
      JonB
      wrote on 28 May 2020, 09:17 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 29 May 2020, 13:59 last edited by
        #3

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

        J 1 Reply Last reply 29 May 2020, 14:05
        0
        • M Moia
          29 May 2020, 13:59

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

          J Offline
          J Offline
          JonB
          wrote on 29 May 2020, 14:05 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 29 May 2020, 14:15 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

            2/5

            28 May 2020, 09:17

            • Login

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