Connect C++ signal to QML function with arguments
-
I know that there is another thread: http://forum.qt.io/topic/15258/connecting-c-signal-to-qml-function-with-arguments but i still can't connect C++ signal to QML function with arguments.
I made:
Connections { target: addTabq onTest: { console.log(nick) } }
addTabq is a function, Test is a name of the signal, and nick is parameter of signal.
I'm getting:
QML Connections: Cannot assign to non-existent property "onTest"
Unable to assign a function to a property of any type other than var.
QObject::connect: No such slot ApplicationWindow_QMLTYPE_25_QML_76::addTabq(QString)edit: okay, i understand now that "target" is Object, so i have to set there class, it's "Layout" then, now I'm getting: "Unable to assign undefined to QObject*".
My Connections is under ApplicationWindow, it hasn't got any other parents. -
-
@PSI-lbc Yeah, thank you, i have tried this way, but I just tried passing argument as QString not QVariant.
-
Hi,
It's not clear to me how you set up your C++ code and your QML code. Can you show us more detailed code?
@TheQuakee said:
I just tried passing argument as QString not QVariant.
If you're connecting to a JavaScript function, then your C++ signal needs to use QVariant parameters. All JavaScript functions in QML take parameters of var type, which maps to the QVariant type in C++.