c++ does reads QList<QString> always empty when sent from QML
-
hello guys,
I have this:
qml file:property variant sapSystems: [{"a": 1, "b": 2, "c": 3}, {"a": 4, "b": 5, "c", 6}] Component.onCompleted: { var neco = cpp.connectionTest(sapSystems[1]); // so im sending: {"a": 4, "b": 5, "c", 6} }
and in c++ file i have:
void CPP::connectionTest(QList<QString> connParameters) { qDebug() << connParameters; // debugs "QList()" qDebug() << connParameters.count() << connParameters.size() << connParameters.length(); // debugs: 0 0 0 foreach(auto &x,connParameters) // debugs 0 as connParameters seems to be empty qDebug() << x; }
howcome on C++ side its empty?
-
hello guys,
I have this:
qml file:property variant sapSystems: [{"a": 1, "b": 2, "c": 3}, {"a": 4, "b": 5, "c", 6}] Component.onCompleted: { var neco = cpp.connectionTest(sapSystems[1]); // so im sending: {"a": 4, "b": 5, "c", 6} }
and in c++ file i have:
void CPP::connectionTest(QList<QString> connParameters) { qDebug() << connParameters; // debugs "QList()" qDebug() << connParameters.count() << connParameters.size() << connParameters.length(); // debugs: 0 0 0 foreach(auto &x,connParameters) // debugs 0 as connParameters seems to be empty qDebug() << x; }
howcome on C++ side its empty?
@shokarta said in c++ does reads QList<QString> always empty when sent from QML:
[{"a": 1, "b": 2, "c": 3},
{"a": 4, "b": 5, "c", 6}]This is not a list of strings, but a list of objects. So, sapSystems[1] is {"a": 4, "b": 5, "c", 6} which is not a string.
-
Right, you totaly right...
but QList<QObject> cant be passed to c++ as wrong conversion...any idea how to do what im trying to do?
-
@jsulm said in c++ does reads QList<QString> always empty when sent from QML:
QList<QJsonObject>
TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
i dont know how to pass this objects and read it from c++ :(
unless sending JSON string and recreate it to JSON... which to me is very unnecessary bad practice :(
I would realy prefer to send it and read it in any compatibile way -
@jsulm said in c++ does reads QList<QString> always empty when sent from QML:
QList<QJsonObject>
TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
i dont know how to pass this objects and read it from c++ :(
unless sending JSON string and recreate it to JSON... which to me is very unnecessary bad practice :(
I would realy prefer to send it and read it in any compatibile way -
@shokarta Actually it should be QJsonObject (since {"a": 4, "b": 5, "c", 6} is not a list of objects but an object)
-
@jsulm said in c++ does reads QList<QString> always empty when sent from QML:
QJsonObject
but QJsonObject give the very same error:
TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed.
@shokarta Then try QVariant and try to cast to QJsonObject using https://doc.qt.io/qt-6/qvariant.html#toJsonObject
-
@shokarta Then try QVariant and try to cast to QJsonObject using https://doc.qt.io/qt-6/qvariant.html#toJsonObject
-