Forums

OverviewFelgo 2 Support (Qt 5) › A couple best-practices questions on using Components as pages and properties

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19939

    Felgo User

    Hello,

    A couple quick questions:

    1. I am using Components to load .qml files as pages using navigationStack.push(). Do I understand correctly that Components are not loaded until called? So if I have a number of Components, I can add them all to main.qml as they won’t be loaded into memory until navigationStack.push() is called on them? Or, does Felgo load the Components added to my main.qml file when the app is first run?
      For example: Main.qml:

      import QtQml 2.2
      import QtQuick 2.9
      import Felgo 3.0
      import QtQuick.LocalStorage 2.0
      
      App {
          id: app
          Storage {
              id: myLocalStorage
          }
          Navigation {
              MainMain {} // Home page
              NavigationPage1 {}
              NavigationPage2 {}
          }
          Component {
              id: pageOne
              One {}
          }
          Component {
              id: pageTwo
              Two {}
          }
          Component {
              id: pageThree
              Three {}
          }
          Component {
              id: pageFour
              Four {}
          }
          // There will be quite a few more in my actual code
      }

      If under normal circumstances, most Components listed in the code above won’t be used during a normal user session, should I still place them here or should I only place them on the pages from which the Component page can be accessed?

    2. My second question is about clearing properties when leaving a page. If I load a page and a large amount of data is loaded into a property var when the page is loaded, should I clear that property when I leave the page so long as when the page is returned to, the property will have to be updated anyways. Or, is there some sort of automated way to set this up so memory can be cleared automatically?

    Thank you,
    Eric

    #19942

    Alex
    Felgo Team

    Hi Eric,

    components are partly pre-allocated, to speed up object creation from components. You should not worry about this overhead, this is neglectable.

    Regarding your second question, pages pushed on a NavigationStack are destroyed when popped, and the used memory is freed. Are you referring to all the first-level pages that you switch between with a tab bar or nav drawer? For those pages, it might make sense to manually free the memory of the property (e.g. set to empty object {} or array []). Then the used memory will also be freed.

    Cheers,
    Alex

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support