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. Sending signal from Qt Quick ApplicationWindow to C++ class
Forum Updated to NodeBB v4.3 + New Features

Sending signal from Qt Quick ApplicationWindow to C++ class

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 2.6k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    QTBeginner42
    wrote on last edited by
    #1

    I want to receive a signal of an ApplicationWindow started by a QQmlApplicationEngine in my C++ object.
    But I don't know, how I can connect my Application window with this C++ object, see the '???' comment in my code.

    myObject.cpp
    @
    startApplicationWindow() {
    engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); //engine is a QQmlApplicationEngine
    QObject::connect(/* ??? */, SIGNAL( workDone() ), this, SLOT( doAction() )
    }

    doAction() { //code } //as public slot in myObject.h declared
    @

    main.qml
    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Dialogs 1.1

    ApplicationWindow {
    id : root
    visible: true
    width: 100
    height: 100
    title: qsTr("Window")
    signal workDone()

    Button {
        id: button
        x: 42
        y: 42
        text: qsTr("press")
        onClicked: { workDone() }
    }
    

    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DeeeZ
      wrote on last edited by
      #2

      From QML you can change properties and call method of objects created from C++. So It's not necessary to use a signal

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        Take a look on "Integrating QML and C++":http://qt-project.org/doc/qt-5/qtqml-cppintegration-topic.html and "Exposing Attributes of C++ Types to QML":http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QTBeginner42
          wrote on last edited by
          #4

          Thanks for the answers. In my case it is enough to call a method of the object. It works.

          But is there not a possibility to connect the ApplicationWindow with an object? I think the ApplicationWindow should know so few as possible about the C++ objects.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            Do you mean like described "here":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#connecting-to-qml-signals ?

            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
            0

            • Login

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