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

App

The top-level component of a Felgo application containing all other components. More...

Import Statement: import Felgo 4.0
Inherits:

ApplicationWindow

Properties

Signals

Methods

Detailed Description

The App type is used to create the top-level item in a new Felgo application. Every Felgo app begins with a single App component defined at the root of its hierarchy.

Example Usage

The NavigationStack component adds a navig<ation bar and is used to navigate between pages. The AppPage component is the container for a single page of content.

 import Felgo
 import QtQuick

 App {

   // Displays a navigation bar and is used for navigation between pages
   NavigationStack {

     AppPage {
       title: "Hello Felgo" // Is displayed in the navigation bar

       AppText {
         anchors.centerIn: parent
         text: "Hi :)"
       }
     }
   }
 }

More Navigation Examples

See more app navigation examples here: Navigation Guide

How do I listen to app lifecycle events?

For listening to lifecycle events, you can add handlers for the App::applicationPaused or App::applicationResumed signals:

 import Felgo

 App {

   onApplicationPaused: console.log("Application paused.")
   onApplicationResumed: console.log("Application resumed.")

   // ...
 }

How do I handle landscape transitions in Felgo?

The App::portrait or App::landscape properties allow to optimize your layout for different orientations. Similar other properties in QML, you can add handlers for property changes or use property bindings to adapt the UI automatically.

 import Felgo

 App {
   id: app
   onPortraitChanged: {
     if(portrait)
       console.log("orientation changed to portrait")
     else
       console.log("orientation changed to landscape")
   }

   AppText {
     text: app.landscape ? "Landscape Mode" : "Portrait Mode"
     anchors.centerIn: parent
   }
 }

You can also manually change the orientation settings at runtime, e.g. like this:

 import Felgo
 import QtQuick

 App {
   NavigationStack {
     AppPage {
       title: "Orientation Lock"

       Column {
         AppButton {
           text: "Lock to landscape"
           onClicked: NativeUtils.preferredScreenOrientation = NativeUtils.ScreenOrientationLandscape
         }
         AppButton {
           text: "Remove orientation lock"
           // Resets to the orientation defined in AndroidManifest.xml / Project-Info.plist
           onClicked: NativeUtils.preferredScreenOrientation = NativeUtils.ScreenOrientationDefault
         }
       }
     }
   }
 }

More Frequently Asked Development Questions

Find more examples for frequently asked development questions and important concepts in the following guides:

Property Documentation

[read-only] diameterInInches : real

This read-only property holds the physical diameter of the screen in inches.

You can use it for example to load different layouts based on the physical size.

Note: The tablet property gets true if this property is bigger than 5.3.

See also widthInInches, heightInInches, and tablet.


dpScale : real

The scale factor all dp() values are multiplied with.

The default value is 1.

See also dp(), spScale, and uiScale.


[read-only] heightInInches : real

This read-only property holds the physical height of the screen in inches.

You can use it for example to load different layouts based on the physical size.

See also widthInInches and diameterInInches.


[read-only, since Felgo 2.9.2] isOnline : bool

True if the device is connected to a network, false otherwise.

Note: Since Felgo 4.0, this property is only supported on Android and iOS. On other platforms, it will always contain true. This is because Qt 6 removed network state access through QNetworkConfigurationManager. On mobile platforms, it uses native APIs for accessing network state instead.

Note: Being connected to a network does not mean that the network also provides internet access, or that the network signal and transmission rate is fast enough for your use-case. To determine if your target server can be reached, send an HttpRequest to see if the request goes through and you get a valid response.

This property was introduced in Felgo 2.9.2.


[since Felgo 2.17.1] keyboardHeight : real

Read-only property returning the current height of a keyboard. If there is currently no keyboard visible on screen, it is 0.

 import Felgo
 import QtQuick

 App {
   id: app
   NavigationStack {
     AppPage {
       title: qsTr("KeyboardHeight Example")

       AppTextField {
         height: dp(40)
         width: parent.width - dp(50)
         anchors {
           horizontalCenter: parent.horizontalCenter
           top: parent.top
           topMargin: dp(50)
         }
         backgroundColor: "lightgrey"
         placeholderText: "Enter text here ..."
       }

       Rectangle {
         id: bottomBar
         color: "grey"
         width: parent.width
         height: dp(50)
         anchors {
           bottom: parent.bottom
           bottomMargin: app.keyboardHeight
         }
       }
     }
   }
 }

This property was introduced in Felgo 2.17.1.

See also keyboardVisible.


[since Felgo 2.17.1] keyboardVisible : bool

Read-only property returning true if a keyboard is currently visible on screen, false otherwise.

This property was introduced in Felgo 2.17.1.

See also keyboardHeight.


[read-only] landscape : bool

This read-only property gets true if the device is held in landscape mode. This means, the width is bigger than the height.

You can use it for example to load different layouts if the device is in landscape mode.

Note: If landscape is true, portrait will be false and vice versa.

See also portrait and tablet.


licenseKey : string

Set this property to the key you received from https://felgo.com/license/.

You can generate unlimited keys in the Felgo Free Plan and as a Felgo customer.

You need a generated key in order to publish your app.

See also Felgo License.


Whether the Felgo debug menu bar for resolution and theme changing should be set for the app window. By default, the menu bar is only enabled for non-publishing builds on desktop platforms.

This property was introduced in Felgo 2.8.0.


[read-only, since Felgo 3.9.2] modalCount : int

Returns the total number of currently active AppModal or AppOverlay items within the application.

This property was introduced in Felgo 3.9.2.


[read-only, since Felgo 3.9.2] modalVisible : bool

Whether the application currently shows an AppModal or AppOverlay item on top of other UI items in the application.

This property was introduced in Felgo 3.9.2.


[read-only] portrait : bool

This read-only property gets true if the device is held in portrait mode. This means, the height is bigger than the width.

You can use it for example to load different layouts if the device is in portrait mode.

Note: If portrait is true, landscape will be false and vice versa.

See also landscape and tablet.


[since Felgo 2.8.0] screenHeight : real

Set this property together with screenWidth to specify the default size for the app window when running your application on desktop platforms. The screenHeight specifies the height of the content area within the application window. You can use it to simulate resolutions of different devices, the default screen height is 854 px. Only use these properties for initialization purposes, to change the width or height during runtime, use setScreenSize instead.

Note: The actual window may be bigger than the chosen screen size, for example if a menuBar, header or footer is used.

This property was introduced in Felgo 2.8.0.

See also screenWidth and setScreenSize.


[since Felgo 2.8.0] screenWidth : real

Set this property together with screenHeight to specify the default size for the app window when running your application on desktop platforms. The screenWidth specifies the width of the content area within the application window. You can use it to simulate resolutions of different devices, the default screen width is 480 px. Only use these properties for initialization purposes, to change the width or height during runtime, use setScreenSize instead.

Note: The actual window may be bigger than the chosen screen size, for example if a menuBar, header or footer is used.

This property was introduced in Felgo 2.8.0.

See also screenHeight and setScreenSize.


[since Felgo 2.10.1] settings : Storage

The settings property allows persistent storing key-value pairs of data, that are also available when the user closes the app and restarts it.

The data is stored in a SQLite database with the Storage object, and can be accessed with setValue(key, value) and getValue(key).

As a convenience, often-needed properties are also put into the Settings object to store data needed by most games or apps. That includes user preferences for sound, high score and the user name. These properties are stored automatically to the database when you change them.

As the settings property is defined in the root object App, you can access it from all components in your application.

Note: The value stored to the database, is also available after the user updated the app.

List of Available Settings Properties

These are the properties and their default values that get synchronized with the database automatically:

  • bool soundEnabled: true
  • bool musicEnabled: true
  • int maximumHighscore: 0
  • string username: ""
  • string language: <Current OS Language>

Example Usage

Here is an example how to use the settings object to store a custom property in your app called numberAppStarts.

 import Felgo
 import QtQuick

 App {

   // this property holds how often the app was started
   property int numberAppStarts

   Component.onCompleted: {
     // this code reads the numberAppStarts value from the database

     // getValue() returns undefined, if no setting for this key is found, so when this is the first start of the app
     var tempNumberAppStarts = settings.getValue("numberAppStarts")
     if(tempNumberAppStarts === undefined)
       tempNumberAppStarts = 0
     else
       tempNumberAppStarts++

     settings.setValue("numberAppStarts", tempNumberAppStarts)
     numberAppStarts = tempNumberAppStarts
   }
 }

Using the Language Property

The Settings item provides an easy way to change the language of the app when multiple languages with translation files are used. The property is always up to date and is used to load the last saved language at application start. For more information about translation files and multiple languages see Internationalization with Felgo.

The following example shows how to change the language of the application. Which is translated when the application starts next.

 import Felgo
 import QtQuick

 App {
   AppButton {
     text: "Current Language:" + settings.language
     onClicked: {
       settings.language = "fr_FR";
     }
   }
 }
Prevent Synchronizing the Properties for Testing

In some cases, you may want to avoid the synchronization of the properties during development. For example, you may want to enable or disable the sound based on the debug or release build of the game. So you do not want to store the setting to the database and load it initially, but set it initially to a custom value. The following example shows how to set the soundEnabled property to true in release build and false in debug build:

 import Felgo
 import QtQuick

 App {

    Component.onCompleted: {

      if(system.debugBuild) {
        settings.ignoredPropertiesForStoring = ["soundEnabled"]
        settings.soundEnabled = false
      }
    }
 }

This property was introduced in Felgo 2.10.1.

See also Storage.


[since Felgo 2.8.0] shutdownAppWithEscapeKeyEnabled : bool

This property holds whether an Escape key press closes the app.

The default value is true for Development Builds on Desktop platforms and false for Publish Builds or mobile platforms.

Thus you can quickly shutdown an app on Desktop with the Esc key during development, where closing and restarting an app is often needed.

Note: You can enable a publish build by setting the property "stage": "publish" in your config.json file.

This property was introduced in Felgo 2.8.0.


spScale : real

The scale factor all sp() values are multiplied with.

The default value is 1.

See also sp(), dpScale, and uiScale.


[since Felgo 2.13.2] storeWindowGeometry : bool

Whether the previous Window position and size, uiScale and Theme::platform gets stored and then restored at subsequent app starts.

By default, it has the same value as menuBarFelgoEnabled, which is only true on Desktop platforms and non-publish builds.

This property was introduced in Felgo 2.13.2.


[read-only] tablet : bool

This read-only property gets true if the screen's diameter is bigger than 6.9 inches.

You can use it for example to load different layouts if the device is a tablet.

See also portrait and landscape.


uiScale : real

The scale factor all dp() and sp() values are multiplied with.

The default value is 1 on mobile and 2 on desktop platforms.

See also dp(), sp(), spScale, and dpScale.


[since Felgo 2.10.0] utils : alias

This property is an instance of the Utils component, which allows easy access to often-needed JavaScript functionality.

You can access it from any element in your QML tree with the utils name, because it is contained in the root App element.

The following example shows how to call the Utils::generateRandomValueBetween() method:

 import Felgo

 App {

   Component.onCompleted: {

     // the utils property is available to all elements, because it is contained in the root App element
     console.debug("random value between 10 and 15:", utils.generateRandomValueBetween(10, 15) )
   }
 }

This property was introduced in Felgo 2.10.0.


[since Felgo 3.9.0] webObject : WebObject

A default shared object between this QML engine and a remote JavaScript engine via QWebChannel API, used for sharing default values, like the website title, and using signals to notify that the connection between the QML Engine and the Browser is ready.

 import Felgo

 App {

   // You can disable auto initialization of the WebChannel, to add more control to the connection with the browser
   webObject.autoInitialize: false
   webObject.onClientInitialized: {
     // Browser JS client is Ready, message is a variable sent from the browser
     console.log("Client ready", message)
   }

   // Access the Browser url from QML
   AppText {
     anchors.centerIn: parent
     text: webObject.url
   }

   Component.onCompleted: {
     // Initialize the WebChannel with the browser at your will
     webObject.initializeChannel()
   }
 }

This property was introduced in Felgo 3.9.0.

See also Sharing data with the Browser.


[since Felgo 3.9.0] webObjects : list<QtObject>

Array of shared objects between this QML engine and a remote JavaScript engine via QWebChannel API, mainly used for WebAssembly in order to share data between your Felgo app and the website running it.

This property was introduced in Felgo 3.9.0.

See also Sharing data with the Browser.


[read-only] widthInInches : real

This read-only property holds the physical width of the screen in inches.

You can use it for example to load different layouts based on the physical size.

See also heightInInches and diameterInInches.


Signal Documentation

[since Felgo 4.2.0] appLinkUrlReceived(url appLinkUrl)

This signal is emitted when the application is opened or coming from the background with a universal link (deep link).

The appLinkUrl parameter contains the URL that opened the app.

Use this handler, for example, to navigate to a specific screen or content in your application.

You can learn more about using universal and app links in your app here: Universal and App Links.

Example Usage

 import Felgo

 App {
   onAppLinkUrlReceived: function(appLinkUrl) {
     console.log("Opened with:", appLinkUrl)
   }
 }

Note: The corresponding handler is onAppLinkUrlReceived.

This signal was introduced in Felgo 4.2.0.


applicationPaused()

This signal is emitted when the application is paused. This occurs when the app is moved into the background after pressing the Home button. It is also called when the app is left because the user answers a phone call for example, or when the user locks the screen.

The corresponding handler is onApplicationPaused.

Use this handler to store any app-related data you want to save persistently and should be available to the user after the app is resumed.

If the app got destroyed after the pause, you can then restore the old state when the application starts with Component.onCompleted() or in applicationResumed in case the app was not destroyed but still in the OS memory.

Note: For quick testing of the functionality on desktop systems, you can minimize the application.

As an example, you could put the app into a pause scene once the application is paused. The pause scene could contain a resume button, so the user has enough time to continue with the app after he left the application.

Note: The corresponding handler is onApplicationPaused.

See also applicationResumed.


applicationResumed()

This signal is emitted when the application is resumed after a previous applicationPaused call. It is not called when the application is first started - for this initialization, use the Component.onCompleted() handler.

The corresponding handler is onApplicationResumed.

Use this handler for example to load a previously saved app state. The applicationResumed signal may be called multiple times in an application's lifetime.

Note: The corresponding handler is onApplicationResumed.

See also applicationPaused.


initTheme()

Implement this signal handler to override the app's default theme values on app start. For more information have a look at the Theme global object.

Note: This handler is called after the App and all it's contained objects are already created. Thus if any animations trigger on changes to the theme, these might play on app startup. To prevent this, you can use the Theme::isInitialized property:

 import Felgo
 import QtQuick

 App {
   onInitTheme: {
     Theme.colors.backgroundColor = "black"
   }

   Rectangle {
     anchors.fill: parent
     color: Theme.backgroundColor

     Behavior on color {
       // do not animate the initial color change during onInitTheme
       enabled: Theme.isInitialized

      ColorAnimation { duration: 150; easing.type: Easing.InOutQuad }
     }
   }
 }

Note: The corresponding handler is onInitTheme.


splashScreenFinished()

This handler gets called when the Felgo splash screen was shown and now faded out. It is also called if the license does not require a splash screen, initially at app startup. You can then continue with your app logic in onSplashScreenFinished: ....

Note: A splash screen is only shown in the Felgo Starter License or if you did not set any licenseKey. Upgrade to one of the other licenses to hide the splash screen.

Note: The corresponding handler is onSplashScreenFinished.


Method Documentation

dp(value)

Returns the density-independent unit for this pixel value.

This allows you to define the same physical size for Item elements across platforms and screens with different densities.

DPI Examples

The dp value is calculated with the following formula: dp = pixel * screenDpi / 160

This means:

  • On a 160 dpi screen like the iPhone 3 (non-retina display), the pixel value of 1 will return 1 dp unit.
  • On a 320 dpi screen like the iPhone 4 (retina display), the pixel value of 2 will return 1 dp unit.

Although the pixel values are different, the physical size of them is the same!

160 dp equals 1 inch. You can calculate the inch value from the pixel value with pixelToInches().

Note: The recommended button height is 48dp. This equals 3/10 of an inch or 0.8 centimeters.

You can modify the result of all dp() function calls by changing the dpScale or uiScale properties.

Example Usage

 import Felgo
 import QtQuick

 App {
   id: app

   Rectangle {
     width: parent.width
     height: app.dp(48)

     Text {
       text: "20sp"
       font.pixelSize: app.sp(20)
     }
   }
 }

Also see the guide Density Independence Support: dp, sp, pixelToInches, tablet, orientation for more information on density independence. The Android Developers Guide about Supporting Multiple Screens is also a great read to better understand density independence, as the same concepts of Android are used in Felgo.

See also sp(), dpScale, and uiScale.


physicalPixels(pixel)

Returns the pixel value multiplied with the devicePixelRatio of the screen.

On iOS & Mac devices, the reported screen size of App is a virtual point size. To get the real pixels of the screen, a multiplication with devicePixelRatio is needed.

You will mostly not need this value, but it may be useful for debug output or certain scenarios.

Note: The physicalPixels value of the screen is used in Felgo to choose the default Felgo File Selectors to support Dynamic Image Switching.


pixelToInches(pixel)

Returns the value in inches from the pixel value.

You can use the inch value for example to load different layouts based on the physical size.

See also dp(), sp(), widthInInches, heightInInches, diameterInInches, and tablet.


px(value)

internal


[since Felgo 2.8.0] setScreenSize(newWidth, newHeight)

Directly modifying the screenWidth and screenHeight properties during runtime can lead to unwanted effects. Use this method to safely change the screen size for the application window during runtime.

This method was introduced in Felgo 2.8.0.

See also screenWidth and screenHeight.


sp(value)

Returns the density-independent unit for this pixel value. Only use this function for Text element font.pixelSize values.

This allows you to define the same physical size for Text elements across platforms and screens with different densities.

DPI Examples

The dp value is calculated with the following formula: dp = pixel * screenDpi / 160

This means:

  • On a 160 dpi screen like the iPhone 3 (non-retina display), the pixel value of 1 will return 1 dp unit.
  • On a 320 dpi screen like the iPhone 4 (retina display), the pixel value of 2 will return 1 dp unit.

Although the pixel values are different, the physical size of them is the same!

160 dp equals 1 inch. You can calculate the inch value from the pixel value with pixelToInches().

Note: The recommended button height is 48dp. This equals 3/10 of an inch or 0.8 centimeters.

You can modify the result of all sp() function calls by changing the spScale or uiScale properties.

Note: The only difference to dp() is that you have a different spScale value available to change the scale factor of Text elements. You could read the user settings for font sizes of the system and change it accordingly. This is done by default for native Android applications - you could implement this function yourself by querying the user font settings and then changing the spScale value.

You could also use the spSale to allow users change the font size in your app at runtime, for example with a slider in a settings page.

Example Usage

 import Felgo
 import QtQuick

 App {
   id: app

   Rectangle {
     width: parent.width
     height: app.dp(48)

     Text {
       text: "20sp"
       font.pixelSize: app.sp(20)
     }
   }
 }

Also see the guide Density Independence Support: dp, sp, pixelToInches, tablet, orientation for more information on density independence. The Android Developers Guide about Supporting Multiple Screens is also a great read to better understand density independence, as the same concepts of Android are used in Felgo.

See also dp(), dpScale, and uiScale.


Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded