Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class QMLSignalHandler : public QObject{
  2. public:
  3. explicit QMLSignalHandler(QObject* parent=nullptr) : QObject (parent){}
  4. public slots:
  5. void handleNewTask(){
  6. qDebug() << "Hello";
  7. }
  8. };
  9.  
  10. int main(int argc, char ** argv)
  11. {
  12. QGuiApplication app(argc, argv);
  13.  
  14. QQmlApplicationEngine engine;
  15. const QUrl url(QStringLiteral("qrc:/main.qml"));
  16. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  17. &app, [url](QObject *obj, const QUrl &objUrl) {
  18. if (!obj && url == objUrl)
  19. QCoreApplication::exit(-1);
  20. }, Qt::QueuedConnection);
  21. engine.load(url);
  22. auto *ctxt = engine.rootContext();
  23.  
  24. QQuickWindow * window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0));
  25. QMLSignalHandler handler;
  26.  
  27. //No compile-time error, but as soon as I run, it gives No such slot QObject::handleNewTask()
  28. QObject::connect(window, SIGNAL(addTask()), &handler, SLOT(handleNewTask()));
  29.  
  30. return app.exec();
  31. }
  32.  
  33. Window {
  34. id: rootWindow
  35. width: 300
  36. height: 400
  37. title: qsTr("Hello World")
  38. visible: true
  39. signal addTask
  40. Button{
  41. text: "test"
  42. onClicked: addTask()
  43. anchors.bottom: taskList.bottom
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement