Unsolved Error connecting C++ signal to Qml Slot
-
homePopUp.qml
@
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Popup{
id: pop
function setSourceComp(status)
{
console.log("signal received",status);
}
Connection{
target: home
onDoSetSourceComp: {
setSourceComp(status) // ReferenceError: status is not defined
}
...
}
...
}
@in C++ Class I have this signal
@
void doSetSourceComp(QSting status); // on header file
emit doSetSourceComp("success"); // called in source file
@What am i doing wrong here?
-
hi,
@Gurubaran said in Error connecting C++ signal to Qml Slot:
ReferenceError: status is not defined
in homePopUp.qml you should have a ''property string status " do you have it ?
-
@LeLev
No ,I dont have that "property string status". Actually in homePopUp.qml "status" is a function parameter (setSourceComp(status)) not a property. Still I tried it , only the reference error stopped but does not serve my purpose.I want to send a QString from c++ signal to Qml which will be received by this function.
When I add debug message inside
@
onDoSetSourceComp: {
console.log("Signal received") // this gets printed when the c++ signal is emitted
setSourceComp(status) // ReferenceError: status is not defined
}
@Is there any other suggesions?
-
@Gurubaran ok,
when you writesetSourceComp(status) // ReferenceError: status is not defined
you are calling setSourceComp() with param status so status must be defined;
if that string is a Q_Property of your class do :onDoSetSourceComp: { setSourceComp(home.status) // ReferenceError: status is not defined }
-
@Gurubaran
just to make sure those are typos:
the element should beConnections
, you wroteConnection
You signal parameter is of the typeQSting
instead ofQString
Where does the
home
target come from?!
If it is set as a context property you need to callqmlRegisterType()
(or one of it's "sibling" methods) to let the QML engine know it's properties and signals properly.