Compile error in qjsonrpcservice.cpp (gcc 4.6.3-1ubuntu5 and Qt 4.8.2)

Issue #14 resolved
Ricardo Costa created an issue

I get the following error when compiling on Ubuntu 12.04 with GCC 4.6.3 and Qt 4.8.2:

../../src/qjsonrpcservice.cpp: In function QVariant convertArgument(const QJsonValue&, const QJsonRpcServicePrivate::ParameterInfo&):
../../src/qjsonrpcservice.cpp:211:40: error: call of overloaded QVariant(const int&, NULL) is ambiguous
../../src/qjsonrpcservice.cpp:211:40: note: candidates are:
/usr/include/qt4/QtCore/qvariant.h:436:12: note: QVariant::QVariant(bool, int)
/usr/include/qt4/QtCore/qvariant.h:170:5: note: QVariant::QVariant(int, const void*)
../../src/qjsonrpcservice.cpp: In member function bool QJsonRpcService::dispatch(const QJsonRpcMessage&):
../../src/qjsonrpcservice.cpp:328:67: error: call of overloaded QVariant(QMetaType::Type&, NULL) is ambiguous
../../src/qjsonrpcservice.cpp:328:67: note: candidates are:
/usr/include/qt4/QtCore/qvariant.h:436:12: note: QVariant::QVariant(bool, int)
/usr/include/qt4/QtCore/qvariant.h:170:5: note: QVariant::QVariant(int, const void*)

Replacing NULL by C++11's nullptr keyword on both call sites solves the problem.

Comments (8)

  1. Matt Broadstone

    hmm, we can't use nullptr since we can't assume c++11 support until qt5. Unfortunately I also don't have access to such an old version of Qt, could you propose a portable alternative? Perhaps one that we can include just as an ifdef for Qt < 4.8.6

  2. Ricardo Costa reporter

    Hm yes, we can explicitly cast NULL to const char* to avoid the ambiguity, as follows:

    Line 211: return QVariant(info.type, (const char*)NULL);

    Line 328: QVariant() : QVariant(returnType, (const char*)NULL);

  3. Matt Broadstone

    Can you please try building the "issue-14" branch and let me know if it compiles fine on your version of Qt? I suspect this change made it in from another submitted PR, as I generally don't use the NULL keyword (simply using 0 might have worked as well).

  4. Log in to comment