Important: Please read the Qt Code of Conduct -

QML signal from Loaded qml to slot in c++

  • quick background: I'm working with embedded Linux with eglfs. If you are unfamiliar with eglfs its not important except that it only allows 1 single window to exist and be rendered. Aur app uses QQmlApplicationEngine. Loading the first qml page works fine. Any attempt to unload said page and load a different one results in an eglfs cannot have multiple windows error. the loaded feature in qml lets us load different pages without error which is fine. So the problem becomes we have many different pages in the app and each page needs signals/slots to c++. The "Issue" is as follows..wait for it: in the Main qml page I have no issues using signals/slots and talking to c++. in the loaded pages however the signals are not visible to c++ without in some way shape or form setting up signals in the main qml page. I don't want to put 50 pages of signals and slots all on the main qml page that's horrible. All the posts say Any qml signal is visible to c++ but I'm not experiencing that, any attempt to put a signal in a loaded qml page will not be seen by a connect in c++. The closest I have come to a solution that would let me keep signals and slots organized by page would be using a custom qml control (a c++ class I can import that exposes stuff. Is there any easier way to do this? Thanks in advance.

  • hi @AFuzzyBadger,
    //PageView.qml // this is First page, auther pages (MyPage1, MyPage2, MyPage3) are inside this page

    import QtQuick 2.0
    Item {
    /*page to show*/
        property int mod:0 // 0>page1; 1>page2; 2>page3
    /*aliases for connections*/
        property alias page1:p_1
        property alias page2:p_2
        property alias page3:p_3
           anchors.fill: parent
           visible: mod===0
            anchors.fill: parent
            visible: mod===1
           anchors.fill: parent
            visible: mod===2

    Juste create that first page in your main + create functions to handle signals from that page:

    function moveHandler() {
    function stopHandler() {
                 mod : 2 // default page will be 'MyPage3'
            height: parent.height
            width: parent.width 
                //Page 3 connect
             //... connect everything 

    //exemple 'MyPage3.qml'

    Item {
        anchors.fill: parent
    /*signals to connect*/   
     signal move()
     signal stop()
                onClicked: move()
                onClicked: stop()

    I hope this can help

  • @AFuzzyBadger It would be easier to give specific solutions if you could provide Minimal, Complete, Verifiable Example. Without it we can only guess.

    I'm guessing these could be useful to you

Log in to reply