I have a function in C++ which is called from my QML code. When the function is void
or returns an int
everything is fine. However when returning a QVariant
and I call the function the function does not excecute.
C++ function
QVariant Wifi::scan(){
QVariantList varlist;
QVariant var;
qDebug("Inside function");
varlist.append("Test1");
varlist.append("Test2");
var = QVariant(varlist);
return var;
}
.h file
include <QVariant>
class Wifi : public QObject
{
Q_OBJECT
public:
Wifi();
Q_INVOKABLE QVariant scan();
Q_INVOKABLE int checkIfConnected();
QStringList* getDevice();
};
In the QML file "Test" prints but "Test2" does not. "Inside function" from the C++ part doesn't print either. so Iäm assuming it gets stuck or something in wifi.scan()
part
console.debug("Test")
var anArray = wifi.scan()
for (var i=0; i<anArray.length; i++)
console.log("Array item:", anArray[i])
console.debug("Test2")
I get no error message of any sort. I have also tried to assign the return value to a "property variant" and just run it on its own (wifi.scan()
) without assigning the return value to anything. Any ideas on what could be the problem?