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. QML opening same QML window RAM issue
Forum Updated to NodeBB v4.3 + New Features

QML opening same QML window RAM issue

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlramwindow
14 Posts 2 Posters 5.2k Views 2 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.
  • RiteshPanchalR Offline
    RiteshPanchalR Offline
    RiteshPanchal
    wrote on last edited by
    #3

    Ya i am creating new component every switch.
    And i know that's the reason that why new ram is assigned.

    But how can i switch without creating the new component and referring the old one.?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #4

      @RiteshPanchal hide and show on switch

      157

      RiteshPanchalR 1 Reply Last reply
      1
      • p3c0P p3c0

        @RiteshPanchal hide and show on switch

        RiteshPanchalR Offline
        RiteshPanchalR Offline
        RiteshPanchal
        wrote on last edited by
        #5

        @p3c0 can you show some code snippet?

        Whenever i switch back to current qml all variable or component created new without preventing the old values

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #6

          @RiteshPanchal From where you are creating these 2 pages you have access to its object. Use them to hide/show. You have already done it:
          rootWindow.visible = false

          May be you are not properly doing it.
          Can you post a minimal complete example ?

          157

          1 Reply Last reply
          1
          • RiteshPanchalR Offline
            RiteshPanchalR Offline
            RiteshPanchal
            wrote on last edited by RiteshPanchal
            #7

            Please find my code
            https://drive.google.com/open?id=0B8d7zQv-G71oMHJjcFBuTnNHTUE

            Thanks in advance.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #8

              @RiteshPanchal So it seems you are creating and loading the Window from one another on keypress. I would suggest you to use a seperate main window which will create and load these 2 (Menu.qml and Startupq.ml) windows. Then on keypress from either of these QML send a signal to the main window to hide/show the other.

              157

              RiteshPanchalR 1 Reply Last reply
              1
              • p3c0P p3c0

                @RiteshPanchal So it seems you are creating and loading the Window from one another on keypress. I would suggest you to use a seperate main window which will create and load these 2 (Menu.qml and Startupq.ml) windows. Then on keypress from either of these QML send a signal to the main window to hide/show the other.

                RiteshPanchalR Offline
                RiteshPanchalR Offline
                RiteshPanchal
                wrote on last edited by
                #9

                @p3c0 How to send signal to main window ?

                And by main windows you are referring some qml file like main_window.qml right?

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #10

                  @RiteshPanchal

                  How to send signal to main window ?

                  Refer the following:
                  http://doc.qt.io/qt-5/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals
                  http://doc.qt.io/qt-5/qtqml-syntax-signals.html#adding-signals-to-custom-qml-types

                  And by main windows you are referring some qml file like main_window.qml right?

                  That is just a name. It can be anything but convention is to use first letter as upper case.
                  So somthing like

                  //MainWindow.qml
                  Window {
                      id: root
                      visible: true
                  
                      //Then here after create and instantiate the other 2 items when required.
                  }
                  

                  157

                  1 Reply Last reply
                  2
                  • RiteshPanchalR Offline
                    RiteshPanchalR Offline
                    RiteshPanchal
                    wrote on last edited by
                    #11

                    Thanks for your reply.

                    It seems complicated for me but I will try this method.
                    Actually i am new to Qt and Qml so i am facing the difficulties.

                    I am use single qml file and create different rectangles for each page there will be no memory issue. I just need to do visible=false for current rectangle and visible=true for new rectangle.

                    But as my code become large it will difficult to review and edit. So i am using different qml files for different pages.
                    As my application is Full Screen i am using ApplicationWindow instead of just rectangle.

                    So is it possible i just create one MainWindow as application window and other pages as just rectangles in different qml files. And show/hide any qml file rectangle from main application window?

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #12

                      @RiteshPanchal

                      So is it possible i just create one MainWindow as application window and other pages as just rectangles in different qml files. And show/hide any qml file rectangle from main application window?

                      Yes.

                      Usually this is only one main window. This will be your ApplicationWindow. Then from here you will launch multiple QML files whose root item better be Item. Launching them from this window will allow you keep a track of launched instances from main window.

                      157

                      1 Reply Last reply
                      1
                      • RiteshPanchalR Offline
                        RiteshPanchalR Offline
                        RiteshPanchal
                        wrote on last edited by
                        #13

                        Thanks for the Reply.

                        @p3c0 said in QML opening same QML window RAM issue:

                        Usually this is only one main window. This will be your ApplicationWindow. Then from here you will launch multiple QML files whose root item better be Item. Launching them from this window will allow you keep a track of launched instances from main window.

                        Can you show me some snippet or example code link?
                        It would be very helpful

                        1 Reply Last reply
                        0
                        • p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #14

                          @RiteshPanchal Ok. Here is a very simplified demo which may help you understand the basics. Once you get familiar with these you can explore other options like StackView or SwipeView which also acts as a container for pages and provides methods for its manipulation.
                          The following example consider Item as root element for the child components. You can change it to Window or whatever and adding its related small changes.

                          //Main window
                          //RootWindow.qml
                          import QtQuick 2.6
                          import QtQuick.Controls 2.0
                          import QtQuick.Window 2.1
                          
                          Window {
                              id: root
                              width: 250
                              height: 250
                          
                              property QtObject obj1
                              property QtObject obj2
                          
                              signal hideObj(QtObject obj)
                          
                              Component.onCompleted: {
                                  root.hideObj.connect(onHideObj)
                              }
                          
                              function onHideObj(obj) {
                                  obj.visible = !obj.visible
                              }
                          
                              Row {
                                  anchors.top: parent.top
                                  Button {
                                      text: "One"
                                      onClicked: {
                                          if(!obj1) {
                                              obj1 = Qt.createComponent("Item1.qml").createObject(root);
                                          }
                                          obj1.visible = true;
                                      }
                                  }
                          
                                  Button {
                                      text: "Two"
                                      onClicked: {
                                          if(!obj2) {
                                              obj2 = Qt.createComponent("Item2.qml").createObject(root);
                                          }
                                          obj2.visible = true;
                                      }
                                  }
                              }
                          }
                          
                          //Item1.qml
                          import QtQuick 2.6
                          
                          Item {
                              id: item1
                              anchors.bottom: parent.bottom
                              anchors.left: parent.left
                              width: 50
                              height: 50
                          
                              Rectangle {
                                  color: "red"
                                  anchors.fill: parent
                                  Text {
                                      anchors.centerIn: parent
                                      text: "Item1"
                                  }
                          
                                  MouseArea {
                                      anchors.fill: parent
                                      onClicked: root.hideObj(obj2)
                                  }
                              }
                          }
                          
                          //Item2.qml
                          import QtQuick 2.6
                          
                          Item {
                              id: item2
                              anchors.bottom: parent.bottom
                              anchors.right: parent.right
                              width: 50
                              height: 50
                          
                              Rectangle {
                                  color: "green"
                                  anchors.fill: parent
                                  Text {
                                      anchors.centerIn: parent
                                      text: "Item2"
                                  }
                          
                                  MouseArea {
                                      anchors.fill: parent
                                      onClicked: root.hideObj(obj1)
                                  }
                              }
                          }
                          

                          The two buttons here creates and shows 1 item each containing a colored rectangle and a text displayed at the bottom. Then after creating these 2 items, try clicking on each individual colored rectangle, it will hide/show other rectangle. This works by sending a signal to the root window from the child component.

                          157

                          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