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. [Solved] How to switch from page1.qml (on image click) by sending a string to page2.qml and vice-a-versa?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to switch from page1.qml (on image click) by sending a string to page2.qml and vice-a-versa?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.5k 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.
  • L Offline
    L Offline
    LakshmiSaripella
    wrote on last edited by
    #1

    Hi,

    I've 2 qml files namely page1.qml and page2.qml.

    page1.qml is my main qml file which is getting loaded having got the command "viewer.setMainQmlFile(QStringLiteral("qml/QmlQml/page1.qml"));"

    I wish to show page2.qml on image click of page1.qml by sending a string. The received string by page2.qml is shown there and on some other event of page2, page1 gets displayed.

    Quick help from some source is awaited.

    Kindly guide me how to proceed.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lucijan
      wrote on last edited by
      #2

      You need to use a Loader and Connections.

      @Item {
      id: mainItem
      width: 600
      height: 400
      Component.onCompleted: pageLoader.setSource("Page1.qml")

              signal loadPage(string pageName)
      
              Loader {
                  id: pageLoader
      
                  anchors.fill: parent
              }
      
              Connections {
                  id: pageConnections
                  ignoreUnknownSignals: true
                  target: pageLoader.item
      
                  onLoadPage: {
                      pageLoader.source = pageName;
                  }
              }
      

      }@

      Try something like this. I don't have time to test this but Connections and Loader are what you'll need.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LakshmiSaripella
        wrote on last edited by
        #3

        [Solved] Thanks. I've applied the above mentioned Loader, Connections and could successfully switch to second qml from first qml and vice-a-versa. I'm yet to try out sending String from second and receiving in first.

        In fact, I wish to send and receive an object of Person class between 2 or multiple qml pages (conditionally). Any inputs on this please?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Lucijan
          wrote on last edited by
          #4

          For sending strings, you can check the code posted above. When you want to switch pages, simply send the loadPage signal and the string as the argument. As you can see, I've used the pageName string to change the page.

          I don't know about the Person class, maybe you can use variant, or perhaps QtObject, but I'm really not sure.

          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