Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class QMLSignalHandler : public QObject{
- public:
- explicit QMLSignalHandler(QObject* parent=nullptr) : QObject (parent){}
- public slots:
- void handleNewTask(){
- qDebug() << "Hello";
- }
- };
- int main(int argc, char ** argv)
- {
- QGuiApplication app(argc, argv);
- QQmlApplicationEngine engine;
- const QUrl url(QStringLiteral("qrc:/main.qml"));
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- &app, [url](QObject *obj, const QUrl &objUrl) {
- if (!obj && url == objUrl)
- QCoreApplication::exit(-1);
- }, Qt::QueuedConnection);
- engine.load(url);
- auto *ctxt = engine.rootContext();
- QQuickWindow * window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0));
- QMLSignalHandler handler;
- //No compile-time error, but as soon as I run, it gives No such slot QObject::handleNewTask()
- QObject::connect(window, SIGNAL(addTask()), &handler, SLOT(handleNewTask()));
- return app.exec();
- }
- Window {
- id: rootWindow
- width: 300
- height: 400
- title: qsTr("Hello World")
- visible: true
- signal addTask
- Button{
- text: "test"
- onClicked: addTask()
- anchors.bottom: taskList.bottom
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement