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. QML signal from Loaded qml to slot in c++
Forum Updated to NodeBB v4.3 + New Features

QML signal from Loaded qml to slot in c++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 1.4k 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.
  • A Offline
    A Offline
    AFuzzyBadger
    wrote on last edited by
    #1

    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.

    E 1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      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
      
      
          MyPage1{
              id:page1
             anchors.fill: parent
             visible: mod===0
          }
          MyPage2{
              id:page2
              anchors.fill: parent
              visible: mod===1
          }
          MyPage3{
              id:page3
             anchors.fill: parent
              visible: mod===2
          }
      }
      

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

      function moveHandler() {
             console.log("move")
          }
      function stopHandler() {
          console.log("stop")  
          }
      
          PageView{
              id:pageView
                   mod : 2 // default page will be 'MyPage3'
              height: parent.height
              width: parent.width 
        
              Component.onCompleted:{
                  //Page 3 connect
                  pageView.page3.move.connect(moveHandler)
                  pageView.page3.stop.connect(stopHandler)
               //... connect everything 
              }
      
          }
      

      //exemple 'MyPage3.qml'

      Item {
          anchors.fill: parent
      /*signals to connect*/   
       signal move()
       signal stop()
              Row{
              Button{
                  text:"Move"
                  onClicked: move()
                       }
              Button{
                  text:"Stop"
                  onClicked: stop()
                          }
      
             }
      }
      

      I hope this can help
      LA

      1 Reply Last reply
      2
      • A AFuzzyBadger

        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.

        E Offline
        E Offline
        Eligijus
        wrote on last edited by
        #3

        @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 https://doc.qt.io/qt-5.10/qml-qtquick-controls2-stackview.html
        http://doc.qt.io/qt-5/qml-qtqml-connections.html.

        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