Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 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

    Eric

    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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded