[SOLVED]Signal to and from my qml file
-
I have decided to make a simple ui with qml, that I want to use from my c++ code.
What I have now are the basics
QApplication app(argc, argv); DataControl *dataControl = new DataControl(); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
I then try to find a qml object using
QObject *container = engine.rootObjects().first()->findChild<QObject*>("dropArea");
and finally I am trying to connect a signal with a slot in my class
QObject::connect(container, SIGNAL(imageLoaded(QString)), dataControl, SLOT(dataUpdate(QString)));
It might be a bit too late and I am doing something really wrong, but the app crashes immediately.
How should I connect and emit signals from qml to c++ in this case?
-
Hi,
Are you sure that container is not null ?
-
@ealione said:
It might be a bit too late and I am doing something really wrong, but the app crashes immediately.
How should I connect and emit signals from qml to c++ in this case?
Run your program using a debugger. What does it tell you when your program crashes? (Note: It might not be related to your signal-slot connection at all)
-
Hello
I have found the solution under the following link:
It works with QT 5.3.1 and QML ( QT Quick 2 )
http://wisol.ch/w/articles/2014-12-15-qt-signal-slots-qml-cpp/
The source code of the example can be found under https://github.com/wisoltech/qt-signal-slot -
@JKSH it is definitely related to the slot signal connection command. But as SGaist said, more than probably my
container
is empty. It is just that after midnight I stop thinking straight :)Hi WMKO3 and thanks for the link. Connecting qml and c++ is of curse something simple, I just get stuck sometimes. I will definitely solve this today and post back what the issue was.