Solved conversion from 'long' to 'const QJsonValue' is ambiguous
-
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);
-
@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);
-
@SPlatten
Look at the types accepted byQJsonValue
constructor in https://doc.qt.io/qt-5/qjsonvalue.html. At a guess, yours match eitherint
orqint64
. So cast your value to whichever of the two you desire? -
@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);
-
@SPlatten
I think, but don't quote me: all of your first 5 are "small" and promote/coerce toint
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 sureint
will do it, while preserving sign/value correctly. They might all needqint64
to be sure, so that's why it's "ambiguous" between that andint
. [Actually, I think you can quote me ;-) ]