Qt 从QML到C+的信号+;插槽,找不到QML信号 我在QML得到了一个信号,我想连接到C++中定义的时隙。但是,我的代码失败,我收到了错误:

Qt 从QML到C+的信号+;插槽,找不到QML信号 我在QML得到了一个信号,我想连接到C++中定义的时隙。但是,我的代码失败,我收到了错误:,qt,qml,signals-slots,qtquick2,Qt,Qml,Signals Slots,Qtquick2,QObject::connect:在../qt_cpp/mainwindow.cpp:66中没有这样的信号QDeclarativeContext::sent() 这里是一个C++代码片段: message_reading test; QDeclarativeView tempview; tempview.setSource(QUrl("qrc:/qml/media_screen.qml")); QObject *item = tempview.rootContext(); QObject::co

QObject::connect:在../qt_cpp/mainwindow.cpp:66中没有这样的信号QDeclarativeContext::sent()

这里是一个C++代码片段:

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&)));
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"
        }
    }
}
下面是一个QML代码片段:

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&)));
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"
        }
    }
}

connect
行中的
SIGNAL
宏调用必须使用
SIGNAL(sent(QString))
明确通知参数

此外,该信号是由创建的对象发出的,但您提供的代码段试图将其连接到上下文对象中。您将需要以下内容:

QObject *tempitem = tempview.rootObject();

文档中有一个封面。

没有,我试图在那里添加类型信号(sent(QString)),但它不起作用。报告相同的错误消息,顺便说一句,编译成功,但是当打开应用程序窗口时,返回此错误消息。啊,对不起,现在我注意到您还试图将其附加到上下文,这不是您想要的。将更新答案。无论如何,谢谢您。我有一些新的更新。。。但仍在学习这一点。你的更新实际上提出了一个不同的问题。我相信答案中的两点实际上解决了你原来的问题。