Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to hook up to the onClick event of a QML item from C++ side using the QQuickItem pointer to the QML item

How to hook up to the onClick event of a QML item from C++ side using the QQuickItem pointer to the QML item

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 678 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.
  • N Offline
    N Offline
    Nelson_Piquet
    wrote on last edited by
    #1

    Scenario:
    I have a Qt app which runs on Qt 5.9.4 commercial edition. Its a QtQuick and QML based application which is running on iOS and Android.

    I have a QML item on the UI like this:

    SomeItem {
        text: qsTr("Some Item")
        objectName: "someitem"
        visible: false
        onClicked: {
            console.log("Some item was clicked")
        }
    }
    

    I have a C++ function which can easily control the properties of SomeItem.

    void MyCppClass::Func() {
    
        QQuickItem *someItem = qml_engine->rootObjects()[0]->findChild<QQuickItem*>("someitem");
        someItem->setVisible(true); // this works
    
        // How to listen to someItem's onClick event here
    }
    

    Question:
    I want to listen to the onClick event of someItem in a C++ method or a lambda without changing anything in the QML. Basically hook up to the onClick signal signal of someItem from C++ side itself. How can I do it?

    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