Solved Can C++ signal be called from QML
-
class Hello : public QObject { Q_OBJECT signals: void sampleSignal(); }; // main.cpp Hello obj; engine.rootContext()->setContextProperty("Hello", (*QObject) (&obj)); // QML MouseArea { anchors.fill: parent onClicked: { Hello.sampleSignal() } }
I tried calling c++ signal from QML. Seems to be working fine. But i could not find any documentation for it.
So i just need to know, if this is valid ? -
@Vinoth-Rajendran4 said in Can C++ signal be called from QML:
Can you please direct me to the documentation link if any available ?
Take a look at this: https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-signals
Any public signal of a QObject-derived type is accessible from QML code.
The QML engine automatically creates a signal handler for any signal of a QObject-derived type that is used from QML. Signal handlers are always named on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. All parameters passed by the signal are available in the signal handler through the parameter names.
-
@Vinoth-Rajendran4 said in Can C++ signal be called from QML:
So i just need to know, if this is valid ?
Yes.
-
@sierdzio : Thanks .. But i could not find any documentation regarding this. Can you please direct me to the documentation link if any available ?
-
@Vinoth-Rajendran4 said in Can C++ signal be called from QML:
Can you please direct me to the documentation link if any available ?
Take a look at this: https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-signals
Any public signal of a QObject-derived type is accessible from QML code.
The QML engine automatically creates a signal handler for any signal of a QObject-derived type that is used from QML. Signal handlers are always named on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. All parameters passed by the signal are available in the signal handler through the parameter names.