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. conversion from 'long' to 'const QJsonValue' is ambiguous

conversion from 'long' to 'const QJsonValue' is ambiguous

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.7k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I want to insert certain unsigned data types into a QJsonObject, when I try this I get the message to the right of the line, black in a red background:

    conversion from 'type' to const QJsonValue' is ambiguous
    

    Where 'type' is actual type name. This occurs on:

    uint
    long
    ulong
    

    Is there anything I can do to fix this, each line looks almost the same with the only difference being the insertion of the type:

    objResponse.insert(clsModFileIO::mscszData, lngData);
    

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      @SPlatten
      Look at the types accepted by QJsonValue constructor in https://doc.qt.io/qt-5/qjsonvalue.html. At a guess, yours match either int or qint64. So cast your value to whichever of the two you desire?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by SPlatten
      #3

      @JonB , thank you, I'm a bit confused as I don't get the warning on:

      char
      uchar
      int
      short
      ushort
      

      But I do get the warning on:

      long
      uint
      ulong
      

      Looking on that page it details:

      QMetaType::Int
      QMetaType::UInt
      QMetaType::LongLong
      QMetaType::ULongLong
      QMetaType::Float
      QMetaType::Double
      

      As all having a destination type of QJsonValue::Double, but the warnings I'm seeing do not echo that.

      I've fixed the warnings by adding for each location that has this warning:

      qint64 int64Data = static_cast<qint64>(ulngData);                                        
      objResponse.insert(clsModFileIO::mscszData, int64Data);                                                                                
      

      Kind Regards,
      Sy

      JonBJ 1 Reply Last reply
      0
      • SPlattenS SPlatten

        I want to insert certain unsigned data types into a QJsonObject, when I try this I get the message to the right of the line, black in a red background:

        conversion from 'type' to const QJsonValue' is ambiguous
        

        Where 'type' is actual type name. This occurs on:

        uint
        long
        ulong
        

        Is there anything I can do to fix this, each line looks almost the same with the only difference being the insertion of the type:

        objResponse.insert(clsModFileIO::mscszData, lngData);
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @SPlatten
        Look at the types accepted by QJsonValue constructor in https://doc.qt.io/qt-5/qjsonvalue.html. At a guess, yours match either int or qint64. So cast your value to whichever of the two you desire?

        SPlattenS 1 Reply Last reply
        2
        • JonBJ JonB

          @SPlatten
          Look at the types accepted by QJsonValue constructor in https://doc.qt.io/qt-5/qjsonvalue.html. At a guess, yours match either int or qint64. So cast your value to whichever of the two you desire?

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @JonB , thank you, I'm a bit confused as I don't get the warning on:

          char
          uchar
          int
          short
          ushort
          

          But I do get the warning on:

          long
          uint
          ulong
          

          Looking on that page it details:

          QMetaType::Int
          QMetaType::UInt
          QMetaType::LongLong
          QMetaType::ULongLong
          QMetaType::Float
          QMetaType::Double
          

          As all having a destination type of QJsonValue::Double, but the warnings I'm seeing do not echo that.

          I've fixed the warnings by adding for each location that has this warning:

          qint64 int64Data = static_cast<qint64>(ulngData);                                        
          objResponse.insert(clsModFileIO::mscszData, int64Data);                                                                                
          

          Kind Regards,
          Sy

          JonBJ 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @JonB , thank you, I'm a bit confused as I don't get the warning on:

            char
            uchar
            int
            short
            ushort
            

            But I do get the warning on:

            long
            uint
            ulong
            

            Looking on that page it details:

            QMetaType::Int
            QMetaType::UInt
            QMetaType::LongLong
            QMetaType::ULongLong
            QMetaType::Float
            QMetaType::Double
            

            As all having a destination type of QJsonValue::Double, but the warnings I'm seeing do not echo that.

            I've fixed the warnings by adding for each location that has this warning:

            qint64 int64Data = static_cast<qint64>(ulngData);                                        
            objResponse.insert(clsModFileIO::mscszData, int64Data);                                                                                
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @SPlatten
            I think, but don't quote me: all of your first 5 are "small" and promote/coerce to int automatically, and that's what the compiler will pick. For your second group of 3, the ones you are getting the error on, if you think about you can see the compiler can't be sure int will do it, while preserving sign/value correctly. They might all need qint64 to be sure, so that's why it's "ambiguous" between that and int. [Actually, I think you can quote me ;-) ]

            1 Reply Last reply
            4

            • Login

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