Sending signal from Qt Quick ApplicationWindow to C++ class
-
I want to receive a signal of an ApplicationWindow started by a QQmlApplicationEngine in my C++ object.
But I don't know, how I can connect my Application window with this C++ object, see the '???' comment in my code.myObject.cpp
@
startApplicationWindow() {
engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); //engine is a QQmlApplicationEngine
QObject::connect(/* ??? */, SIGNAL( workDone() ), this, SLOT( doAction() )
}doAction() { //code } //as public slot in myObject.h declared
@main.qml
@
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.1ApplicationWindow {
id : root
visible: true
width: 100
height: 100
title: qsTr("Window")
signal workDone()Button { id: button x: 42 y: 42 text: qsTr("press") onClicked: { workDone() } }
}
@ -
From QML you can change properties and call method of objects created from C++. So It's not necessary to use a signal
-
Take a look on "Integrating QML and C++":http://qt-project.org/doc/qt-5/qtqml-cppintegration-topic.html and "Exposing Attributes of C++ Types to QML":http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html
-
Thanks for the answers. In my case it is enough to call a method of the object. It works.
But is there not a possibility to connect the ApplicationWindow with an object? I think the ApplicationWindow should know so few as possible about the C++ objects.
-
Hi and welcome to devnet,
Do you mean like described "here":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#connecting-to-qml-signals ?