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 Lifecycle

QML Lifecycle

Scheduled Pinned Locked Moved QML and Qt Quick
windowmemory
2 Posts 2 Posters 2.1k 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.
  • E Offline
    E Offline
    emppu
    wrote on 27 Mar 2015, 01:39 last edited by
    #1

    I have a main window, and it has the menu to show a typical 'About..' window.

    ApplicationWindow {
        id: main
        title: qsTr("Hello World")
        width: 640
        height: 480
        visible: true
    
        menuBar: MenuBar {
            Menu {
                title: qsTr("mac")
                MenuItem {
                    text: qsTr("about")
                    onTriggered: {
                        var component = Qt.createComponent("About.qml");
                        var about = component.createObject(main);
                        about.show();
                    }
                }
    ...
    
    1. How to prevent that a user opens the same window twice? Do I need a flag variable in C++ code or is it easily done in QML? This seems a common workflow (preference window, open/save dialog, etc). I don't want to disable the main window while About window is open.

    2. If I keep an instance of About window as an attribute of main ApplicationWindow, does it occupy the memory since the main window is loaded? If I have many different windows, this is really inefficient. What's the simplest solution?

    P 1 Reply Last reply 27 Mar 2015, 10:07
    0
    • E emppu
      27 Mar 2015, 01:39

      I have a main window, and it has the menu to show a typical 'About..' window.

      ApplicationWindow {
          id: main
          title: qsTr("Hello World")
          width: 640
          height: 480
          visible: true
      
          menuBar: MenuBar {
              Menu {
                  title: qsTr("mac")
                  MenuItem {
                      text: qsTr("about")
                      onTriggered: {
                          var component = Qt.createComponent("About.qml");
                          var about = component.createObject(main);
                          about.show();
                      }
                  }
      ...
      
      1. How to prevent that a user opens the same window twice? Do I need a flag variable in C++ code or is it easily done in QML? This seems a common workflow (preference window, open/save dialog, etc). I don't want to disable the main window while About window is open.

      2. If I keep an instance of About window as an attribute of main ApplicationWindow, does it occupy the memory since the main window is loaded? If I have many different windows, this is really inefficient. What's the simplest solution?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 27 Mar 2015, 10:07 last edited by
      #2

      @emppu

      How to prevent that a user opens the same window twice? Do I need a flag variable in C++ code or is it easily done in QML? This seems a common workflow (preference window, open/save dialog, etc). I don't want to disable the main window while About window is open.

      You can do it right itself in QML. Declare component as global property and then check for null before creating that component.

      property Component component
      ...
      MenuItem {
        ...
        onTriggered: {
          if(!component) {
              component = Qt.createComponent("About.qml");
              var about = component.createObject(main);
              about.show();
          }
        }
      }
      

      In my case main window didn't disable. Did you set any particular Qt::WindowFlags flag ?

      If I keep an instance of About window as an attribute of main ApplicationWindow, does it occupy the memory since the main window is loaded? If I have many different windows, this is really inefficient. What's the simplest solution?

      Anything instantiated will occupy memory. To delay that process you use the technique you mentioned or you can use Loader to load them dynamically.

      157

      1 Reply Last reply
      0

      1/2

      27 Mar 2015, 01:39

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved