Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
C++/Qt - Optional parameter default NULL

Some weeks ago, I wrote a little JSON-RPC implemention on my Windows Notebook based on C++ and Qt. I used the Visual C++ 2013 compiler and it worked without any problems.

Now I copied my code to an Linux Mint machine with an GCC compiler and I always get the following error:

jsonrpc.h:18: Error: conversion from 'long int' to 'QJsonValue' is ambiguous
     static QJsonObject generateErrorObj(ErrorCode code, QString message, QJsonValue data = NULL);

This error also appears on line 19 (method generateErrorResponse) and line 20 (method generateRequest). So... now I'm not that familiar with C++ or Qt, so I don't get it, why this doesn't work, althought it worked on Windows...

Here is the full code of the jsonrpc.h:

#ifndef JSONRPC_H
#define JSONRPC_H

#include <QtCore>

class JSONRPC
{
public:
    enum ErrorCode
    {
        PARSE_ERROR = -32700,
        INVALID_REQUEST = -32600,
        METHOD_NOT_FOUND = -32601,
        INVALID_PARAMS = -32602,
        INTERNAL_ERROR = -32603
    };
    static QJsonObject generateObj(QString id, bool isNotification = false);
    static QJsonObject generateErrorObj(ErrorCode code, QString message, QJsonValue data = NULL);
    static QJsonObject generateErrorResponse(QString id, ErrorCode code, QString message, QJsonValue data = NULL);
    static QJsonObject generateRequest(QString id, QString method, QJsonValue parameters = NULL, bool isNotification = false);
    static QJsonObject generateResponse(QString id, QJsonValue result);
};

#endif // JSONRPC_H
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

NULL is likely implemented in a different way on both platforms. The "problematic" implementation creates an ambiguity as there is more than one likely candidate for implicit conversion.

Instead of JsonValue parameters = NULL try JsonValue parameters = JsonValue() - that constructor will create a json value of type null.

Furthermore, even if JsonValue parameters = NULL "works" it will likely be wrong, as it will be equal to something like JsonValue(int(0)) and not a "null" json value as in JsonValue() which has a default QJsonValue::Type::Null parameter. So you won't have a NULL json value, but a NUMBER json value with value of 0 - two completely different things.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!