I'm trying to transfer some QString from c++ to QML. Here are the steps I've done so far.
- Created a class inherited from QObjectand definedsignalin it.
class exampleClass: public QObject {
Q_OBJECT
signals:
void mySignal (QString myStr);
}
- Somewhere in the class implementation, I emitthesignali.e.
void exampleClass::exampleFtn( . . . ){
.
.
qDebug("Before transmitting Signal");        // This gets triggered
emit mySignal ("Hello from CPP");
}
- In my main.cpp, I've initialized the class and expose it toQMLi.e.
int main(...) {
.
.
exampleClass *exampleObj= new exampleClass(&app);
Engine.rootContext()->setContextProperty("exampleObj",  exampleObj);
}
- And finally, in QMLi have connected thesignali.e.
Window {
.
.
Connections {
        target: exampleObj
        function mySignal(myStr) {
            console.log("signal from C++ recieved !")    // Doesn't get triggered
            console.log(myStr)                           //  Doesn't get triggered
        }
    }
}
 
    