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 two connect two qml file using simple buttom
Qt 6.11 is out! See what's new in the release blog

how two connect two qml file using simple buttom

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 5 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.
  • P Offline
    P Offline
    preeth
    wrote on last edited by
    #1

    can anybody give a simple program to connect 2 qml files. when a button is clicked in one qml, the other qml file should open, please help,

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

      I think you misunderstand the concept behind QML and parent-child hierarchy. But, to answer your query: use Loader element.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        preeth
        wrote on last edited by
        #3

        @sierdzio
        i am very new to qml,
        can you please explain with a code snippet

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Beberd
          wrote on last edited by
          #4

          I have do this with an Loader Item.
          example:
          @ Item {
          anchors.fill: parent
          width: parent.width
          height: parent.height

              Loader {
                  id: pageLoader
                   }
          

          }@

          When the button is clicked, you emit a signal changePage().

          And you can write a slot like this:
          @ function getHomePage()
          {
          pageLoader.source = "home.qml";
          }
          @
          Then you connect the slot and the signal in the main.

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

            Please wrap your code in '@' tags. And thanks for that snippet, I was too busy to answer myself.

            (Z(:^

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wspilot
              wrote on last edited by
              #6

              [quote author="sierdzio" date="1364280636"]I think you misunderstand the concept behind QML and parent-child hierarchy. But, to answer your query: use Loader element.[/quote]

              I am suffering from the same problem (not understanding the concept behind QML and parent-child hierarchy).
              Have been searching for hours. Is there a link explaining this topic?
              Need to keep all QML pages in memory (for they need to stay connected to C++), so loader will not do the job.
              Thanks.

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

                After the Loader finishes loading the file, it's content (available under item property) works the same as content loaded on application startup, and can be connected with C++ just the same.

                Search Qt documentation, it's very helpful in most cases. And for QML - create some example projects. It takes a day or two to get used to the idea (declarative world is different from imperative one, after all), then it's all nice and rosy ;)

                (Z(:^

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alek Śmierciak
                  wrote on last edited by
                  #8

                  wspilot, you should create another topic and state your exact issue or goal. Other than that, you ought to have a look at some ready C++&QtQuick examples out there and practice, like sierdzio has already said.

                  "QDeclarative code samples":http://doc.qt.digia.com/4.7/qdeclarativeexamples.html

                  "QtQuick 2 code samples":http://qt-project.org/doc/qt-5.0/qtquick/qtquick2-qtquick-codesamples.html

                  Game example: "5-in-a-row":http://quitcoding.com/?page=work#5inarow

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wspilot
                    wrote on last edited by
                    #9

                    Thanks.
                    Have done that for weeks. Have several Sailfish and plain QML sandboxes set up (but basically for C++/openGL <> QML testing).
                    I now need to navigate between the QML pages (and keep them in memory). In the normal GUI world very simple: hide, show, popup etc., but I cannot find sth. simular in QML.

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

                      @
                      visible = false;
                      @

                      Every Item has this property ;)

                      (Z(:^

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        wspilot
                        wrote on last edited by
                        #11

                        Aha.
                        So, I'll create one main.qml with the specific UI pages based on components and use visible as switch.
                        Thanks.

                        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