0

my problem is, that I can't get a signal and slot connections between a cpp and a qml file. First of all I've found some solutions in the web, but it doesn't work. I'm sure, that the mistake is mine, but I didn't find it.

main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QQmlContext>
#include "Hotfolder.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QScopedPointer<cReadJson> jsonReader(new cReadJson);
    QScopedPointer<cHotfolder> hotfolder(new cHotfolder);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    engine.rootContext()->setContextProperty("jsonReader", jsonReader.data());
    engine.rootContext()->setContextProperty("hotfolder", hotfolder.data());

    QObject *topLevel = engine.rootObjects().at(0);
   QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

    QObject::connect(&cHotfolder, SIGNAL(sigNewOrder()), window, SLOT(
  //  Here is the mistake, that I can't find the Slot in QML
   return app.exec();
}

This is my main.cpp file. In this file I found the Signal from the cpp file, but not the Slot in QML.

main.qml:

function bla()
{
    console.log("bla")
}

This is the function in my main.qml file.

So where ist mistake?

Many thanks in advance!

Ben

1 Answers1

0

The solution is:

Just connect to the signal from within QML and not from C++

example:

Component.onCompleted: hotfolder.sigNewOrder.connect(bla)