QML Warnings
-
**Hello everyone,
I'm currently facing some warnings while compiling my QML application, and I'm not quite sure how to resolve them. Here are the warnings I'm getting:
qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginFailed" qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginCorrect" qml/pages/LoginPage.qml:21: ReferenceError: g_apiManager is not defined qml/pages/LoginPage.qml:22:5 Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.Here's the relevant code snippet from LoginPage.qml:
function loginCorrectHandler(token) { console.log("Token:", token) } Connections { target: g_apiManager onLoginCorrect: { loginCorrectHandler(token) } onLoginFailed: { console.log("Login failed") } }And here's the corresponding C++ code:
Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed();main.cpp
ApiManager g_apiManager; engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);Everything works perfectly fine, but i dont know how to get rid of these warnings.
Could anyone please help me understand how to resolve these warnings?Thank you in advance for your help!
-
**Hello everyone,
I'm currently facing some warnings while compiling my QML application, and I'm not quite sure how to resolve them. Here are the warnings I'm getting:
qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginFailed" qml/pages/LoginPage.qml:20:3: QML Connections: Cannot assign to non-existent property "onLoginCorrect" qml/pages/LoginPage.qml:21: ReferenceError: g_apiManager is not defined qml/pages/LoginPage.qml:22:5 Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.Here's the relevant code snippet from LoginPage.qml:
function loginCorrectHandler(token) { console.log("Token:", token) } Connections { target: g_apiManager onLoginCorrect: { loginCorrectHandler(token) } onLoginFailed: { console.log("Login failed") } }And here's the corresponding C++ code:
Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed();main.cpp
ApiManager g_apiManager; engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);Everything works perfectly fine, but i dont know how to get rid of these warnings.
Could anyone please help me understand how to resolve these warnings?Thank you in advance for your help!
@Veltroniv said in QML Warnings:
Q_INVOKABLE void loginCorrect(const QString& token);
Q_INVOKABLE void loginFailed();these funcs are not signals. your Connections treat them as signals.
Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed(); -
@Veltroniv said in QML Warnings:
Q_INVOKABLE void loginCorrect(const QString& token);
Q_INVOKABLE void loginFailed();these funcs are not signals. your Connections treat them as signals.
Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed(); -
@JoeCFD
so is any option to remove those warnings? in my cpp.h i declared them as signals.signals: Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed();or it is what it is ?
@Veltroniv
ReferenceError: g_apiManager is not definedshow more code about
ApiManager g_apiManager; engine.rootContext()->setContextProperty("g_apiManager", &g_apiManager);Bob64 is right. If the funcs are signals, Q_INVOKABLE is not needed.
-
@JoeCFD
so is any option to remove those warnings? in my cpp.h i declared them as signals.signals: Q_INVOKABLE void loginCorrect(const QString& token); Q_INVOKABLE void loginFailed();or it is what it is ?
@Veltroniv remove
Q_INVOKABLE. Marking a function asQ_INVOKABLEmakes it callable from QML, so you would expect to use it like this in QML code:g_apiManager.loginCorrect("token");Q_INVOKABLEis more like making a function aslot. -
@Veltroniv remove
Q_INVOKABLE. Marking a function asQ_INVOKABLEmakes it callable from QML, so you would expect to use it like this in QML code:g_apiManager.loginCorrect("token");Q_INVOKABLEis more like making a function aslot.@Bob64, I changed the placement of the engine.rootContext(...) line, moving it after the initialization of engine. Now, I don't get such errors. I placed it before the
felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));line, and it works. The warnings disappear.I'm left with only one warning now:
Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.So, I emit the signal from C++ as emit LoginCorrect(token), and I'm trying to catch that in QML by:
function loginCorrectHandler(token) { console.log("Token:", token) } Connections { target: g_apiManager onLoginCorrect: { loginCorrectHandler(token) } onLoginFailed: { console.log("Login failed") } }It's pointing out that I'm using deprecated functions. How should I do it correctly?
//EDIT
That was quite easy, i did it by:onLoginCorrect: function (token) { console.log("Token:", token) }Correct me if im wrong. Thanks :)
-
V Veltroniv has marked this topic as solved on
-
@Bob64, I changed the placement of the engine.rootContext(...) line, moving it after the initialization of engine. Now, I don't get such errors. I placed it before the
felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));line, and it works. The warnings disappear.I'm left with only one warning now:
Parameter "token" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.So, I emit the signal from C++ as emit LoginCorrect(token), and I'm trying to catch that in QML by:
function loginCorrectHandler(token) { console.log("Token:", token) } Connections { target: g_apiManager onLoginCorrect: { loginCorrectHandler(token) } onLoginFailed: { console.log("Login failed") } }It's pointing out that I'm using deprecated functions. How should I do it correctly?
//EDIT
That was quite easy, i did it by:onLoginCorrect: function (token) { console.log("Token:", token) }Correct me if im wrong. Thanks :)
@Veltroniv the preferred
Connectionssyntax is now:Connections { function onLoginCorrect(token) { console.log("Token: ", token); } }