3

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"
        }
    }
}
0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

No, I tried to add type SIGNAL(sent(QString)) there, and it not working. report same error message BTW, compile success, but when open the application window, then return this error message.
Ah, sorry, now I notice you're also trying to attach it to the context, which isn't what you want. Will update the answer.
thank you anyway. I got some new update... but still learning this .
Your update actually asks a different question. I believe the two points in the answer actually solve your original one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.