Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal from QML to C++ slot, cannot find the QML signal

I got a signal in QML and I want to connect to a slot defined in C++. However my code is failing and I'm receiving the error:

QObject::connect: No such signal QDeclarativeContext::sent() in ../qt_cpp/mainwindow.cpp:66

Here is a c++ code snippet:

message_reading test;
QDeclarativeView tempview;
tempview.setSource(QUrl("qrc:/qml/media_screen.qml"));
QObject *item = tempview.rootContext();
QObject::connect(item, SIGNAL(sent()),
&test, SLOT(readMediaJSONDatabase(QString&)));

And here is a QML code snippet:

Image {
    id: bluetooth
    source: "images_mediahub/footer_icons/bluetooth_normal.png"
    signal sent(string msg)
    MouseArea {
        anchors.fill:  parent
        onClicked: {
            bluetooth.sent(Test.medialibrarydb.toString())
            info_load.source="./bluetooth.qml"
        }
    }
}
like image 349
zero Avatar asked Dec 19 '25 21:12

zero


1 Answers

The SIGNAL macro call in the connect line must inform the parameter explicitly, with SIGNAL(sent(QString)).

In addition, the signal is being emitted by the created object, but code snippet you provided is trying to connect it in the context object instead. You'll need something along the lines of:

QObject *tempitem = tempview.rootObject();

There's a complete example covering that in the documentation.

like image 152
Gustavo Niemeyer Avatar answered Dec 21 '25 11:12

Gustavo Niemeyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!