Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get value from another qml
Qt 6.12 LTS is out! See what's new in the release blog

How to get value from another qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 872 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.
  • Atr0p0sA Offline
    Atr0p0sA Offline
    Atr0p0s
    wrote on last edited by Atr0p0s
    #1

    Hello everyone!
    I have 2 qml files:
    main.qml that contains StackView and loader of another file:

    Loader {
            id: serportLoader
            active: false
            source: "serialport-view.qml"
        }
    

    On button pressing I push this file to stack:

    serportLoader.active = true;
    stackView.push(serportLoader.item);
    

    The second qml looks like this:

    ColumnLayout {
        SerialPortHandler {
            id: portHandler
            property bool isPortOpened: false
    ...
    

    So, can I somehow get a value of isPortOpened of the portHandler object?

    With console.log(serportLoader.item.portHandler.isPortOpened); I get TypeError: Cannot read property 'isPortOpened' of undefined.

    I just want to get result of the work from the second qml file. Perhaps can you advise a better approach?
    Thanks in advance!

    mzimmersM 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher moved this topic from General and Desktop on
    • Atr0p0sA Atr0p0s

      Hello everyone!
      I have 2 qml files:
      main.qml that contains StackView and loader of another file:

      Loader {
              id: serportLoader
              active: false
              source: "serialport-view.qml"
          }
      

      On button pressing I push this file to stack:

      serportLoader.active = true;
      stackView.push(serportLoader.item);
      

      The second qml looks like this:

      ColumnLayout {
          SerialPortHandler {
              id: portHandler
              property bool isPortOpened: false
      ...
      

      So, can I somehow get a value of isPortOpened of the portHandler object?

      With console.log(serportLoader.item.portHandler.isPortOpened); I get TypeError: Cannot read property 'isPortOpened' of undefined.

      I just want to get result of the work from the second qml file. Perhaps can you advise a better approach?
      Thanks in advance!

      mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      @Atr0p0s I've never tried this with a loader, but you can put a signal in your serialport-view.qml file to return the value of isPortOpened. Maybe someone else can chime in on doing this through a loader...

      Atr0p0sA 2 Replies Last reply
      1
      • mzimmersM mzimmers

        @Atr0p0s I've never tried this with a loader, but you can put a signal in your serialport-view.qml file to return the value of isPortOpened. Maybe someone else can chime in on doing this through a loader...

        Atr0p0sA Offline
        Atr0p0sA Offline
        Atr0p0s
        wrote on last edited by
        #3

        @mzimmers but I can't connect the signal from serial-port.qml with an object from Main.qml because Loader doesn't create an Object from it at startup...

        1 Reply Last reply
        0
        • mzimmersM mzimmers

          @Atr0p0s I've never tried this with a loader, but you can put a signal in your serialport-view.qml file to return the value of isPortOpened. Maybe someone else can chime in on doing this through a loader...

          Atr0p0sA Offline
          Atr0p0sA Offline
          Atr0p0s
          wrote on last edited by
          #4

          @mzimmers I don't know how, but Connection with Loader.item works even if the item is null.

          Connections {
              target: serialportLoader.item
          }
          

          Thank you! :)

          1 Reply Last reply
          1
          • Atr0p0sA Atr0p0s has marked this topic as solved on

          • Login

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