Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]Signal to and from my qml file
Forum Update on Monday, May 27th 2025

[SOLVED]Signal to and from my qml file

Scheduled Pinned Locked Moved QML and Qt Quick
signalslot
6 Posts 4 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ealione
    wrote on 2 Sept 2015, 22:18 last edited by ealione 9 Mar 2015, 20:12
    #1

    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?

    J 1 Reply Last reply 2 Sept 2015, 22:56
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Sept 2015, 22:23 last edited by
      #2

      Hi,

      Are you sure that container is not null ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • E ealione
        2 Sept 2015, 22:18

        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?

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 2 Sept 2015, 22:56 last edited by
        #3

        @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)

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • W Offline
          W Offline
          WMKO3
          wrote on 3 Sept 2015, 06:37 last edited by
          #4

          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

          1 Reply Last reply
          1
          • E Offline
            E Offline
            ealione
            wrote on 3 Sept 2015, 07:21 last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ealione
              wrote on 3 Sept 2015, 20:12 last edited by
              #6

              @SGaist you are right, I was not receiving anything from qml so my container was empty.

              1 Reply Last reply
              0

              1/6

              2 Sept 2015, 22:18

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved