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. How to interact in between two QML screens?

How to interact in between two QML screens?

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

    How to interact in between two QML screens?
    I am creating new QML component/screen by using "createComponent" and "createObject".

    @var component = Qt.createComponent("testQml.qml");
    var sprite = component.createObject(parentWindow, {"x":0, "y":0});
    if(sprite == null)
    {
    console.log("Error creating component\n");
    return;
    }
    console.log("Screen Created\n");
    // Send some data to the newly created screen
    @

    I have some data that I need to pass it to the newly created screen before it displays the UI components.
    I need two way communication in between child and the parent screen.
    I also need to call some function of the parent QML screen from child screen.

    how it is done in the QML?

    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      digitalsurgeon
      wrote on last edited by
      #2

      May be you can use properties and signals to pass data around ?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        at_pradeep
        wrote on last edited by
        #3

        Can you please provide one example for this (using two qml/js files).
        One way I found is common javascript file in between two QML files and from QML file accessing global key value pares (global array) to send and receive parameters across two QML files.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raja26
          wrote on last edited by
          #4

          Here.. Using a common Javascript file to share data.

          Global.js
          @
          .pragma library
          var sharedVariable = null;
          @

          Your Screen1.qml
          @
          import "Global.js" as GlobalJS

          Rectangle {
          MouseArea {
          anchors.fill:parent
          onClicked: GlobalJS.sharedVariable = "This is shared data";
          }
          }
          @

          Your Screen2.qml
          @
          import "Global.js" as GlobalJS

          Rectangle {
          Text {

          text: GlobalJS.sharedVariable
          }
          }
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            at_pradeep
            wrote on last edited by
            #5

            Thanks for the reply

            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