Warning when connecting c++ signal to qml slot

半腔热情 提交于 2020-01-25 15:50:05

问题


I connect a c++ signal to qml function in qt4.8.4. It's working fine but makes warning in application output as below:

Object::connect: No such slot QDeclarativeItem_QML_9::onValue_changed(double) Object::connect: (sender name: 'MyWidget')

I have defined qml slot like this :

import QtQuick 1.0

Item {
    id: root
    property real value : 0

    Connections
        {
            target: controllerObject
            onValue_changed :
            {
                root.value = value
            }
        }
}

And this is my c++ Signal and how it is connected to qml slot :

ui->view->rootContext()->setContextProperty("controllerObject",this);
ui->view->setSource(QUrl("qrc:/myQml.qml"));
ui->view->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
ui->view->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
ui->view->setResizeMode(QDeclarativeView::SizeRootObjectToView);

connect(this,SIGNAL(value_changed(double)),(QObject *)ui->view->rootObject(),SLOT(onValue_changed(double)));

Why is it making that warning?

How to omit the warning?


回答1:


I have defined qml slot like this :

You are wrong. It is not slot definion, it's connection itself (the adding of QML handler for signal value_changed of object controllerObject). That's why you code works. But in this line :

connect(this, SIGNAL(value_changed(double)), (QObject*)ui->view->rootObject(), SLOT(onValue_changed(double)));

You are trying to connect existing signal value_changed to inexisting onValue_changed (obviously, it exists in your code, but not in rootObject of view). That's why you got warning.

Conclusion:
You tried to connect signal twice, but only one method was successful, so code worked well.



来源:https://stackoverflow.com/questions/27097944/warning-when-connecting-c-signal-to-qml-slot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!