I built a quick server using QT Creator on Windows, everything worked perfectly, I tried running The same code on my other Machine(Ubuntu) and I get errors, specially, in this line:
QString max_colorbar = doc["colorbar"].toString();
The error I am getting is:
no match for ‘operator[]’ (operand types are ‘QJsonDocument’ and ‘const char [9]’)
The thing that confuses me is why do I need to change anything if the same code worked on Windows(It's cross platforms), I thought it may be because of QT versions but I checked my version on linux and it is:
QMake version 3.1
Using Qt version 5.9.5
Am I doing anything wrong?
CodePudding user response:
It's because const QJsonValue QJsonDocument::operator[](const QString &key) const function was introduced in Qt5.10
and you ran in on Qt5.9.5
.
You could change your code from
QString max_colorbar = doc["colorbar"].toString();
to as follows which builds on Qt5.9.5 too
QString max_colorbar = doc.object().value("colorbar").toString();