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. Communication between two qml files
Qt 6.11 is out! See what's new in the release blog

Communication between two qml files

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

    Hello, I think this question might be really silly but since am just a few days old in qml. I would like to clarify my silly queries afterall you learn from mistakes.
    I have two qml files. I want the mainfile to communicate wih the other file. Simple example:
    main.qml:
    @Rectangle {
    width: 360
    height: 360
    MouseArea {
    anchors.fill: parent
    onClicked: {
    secondwindow.visible=true
    }
    }
    }
    @

    sub.qml

    @Rectangle {
    id:secondwindow
    width: 100
    height: 62
    color:"REd"
    visible:false
    }
    @

    Onclick event it should display secondwindow which is in another qml file. This is my basic doubt if this is cleared I can proceed further.Thank you in advance.

    Hannah :)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      For a component to be recognised by QML engine, the "sub.qml" needs to begin with a capital letter ("Sub.qml"). Then you can add it as a component to your main.qml like this:
      @
      Sub {
      id: secondwindow
      }
      @

      And now your code should work. Just remember to position the Sub component properly (by anchoring or setting x, y, width, height manually).

      (Z(:^

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hannah24
        wrote on last edited by
        #3

        Oh. Thank you for your valuable suggestion.

        Hannah :)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          john ankanna
          wrote on last edited by
          #4

          hi sierdzio...
          when i try to communicate qml to qml these are the issues

          i am making use of the cascades along with the QtQuick...
          when i try like this it is showing the error
          here Test is my another qml file and this code is inside the main.qml
          thanks in advance
          @
          import bb.cascades 1.3
          import QtQuick 1.1

          Page {

          Container {
              Label {
                  // Localized text with the dynamic translation and locale updates support
                  text: qsTr("Hello World") + Retranslate.onLocaleOrLanguageChanged
                  textStyle.base: SystemDefaults.TextStyles.BigText
              }
              Test{//this is my qml file 
                  
                  
                  
                  id:
              }
              TextField {
                  id:name2    
              }
             
              Button {
                  text: "text me "
                  onClicked: {
                      app.changeView(qsTr("Test.qml"));
                      test.name.text = name2.text
                      
                  }
              }
          }
          

          }
          @

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            john ankanna please put the source code between '@' tags for better readability. Also, please don't hijack other people's threads.

            What error are you getting? I have never coded using Cascades, but maybe your problem lies in QtQml or QtQuick, in which case I might be able to help.

            (Z(:^

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Traxx
              wrote on last edited by
              #6

              You cannot mix BlackBerry Cascade with Qt Quick.You either create Cascade project or Qt Quick project.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Traxx
                wrote on last edited by
                #7

                You cannot mix BlackBerry Cascade with Qt Quick.You either create Cascade project or Qt Quick project.

                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