App

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

Import Statement: import VPlayApps 1.0
Inherits:

ApplicationWindow

Properties

Signals

Methods

Detailed Description

The App type is used to create the top-level item in a new V-Play application.

Every V-Play app begins with a single App component defined at the root of its hierarchy. Every app usually includes a single Navigation and some Page items.

Property Documentation

read-onlydiameterInInches : 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-onlyheightInInches : 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-onlyisOnline : bool

True if the application has access to the internet, false otherwise.

This QML property was introduced in V-Play 2.9.2.


read-onlylandscape : 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://v-play.net/license/.

You can generate unlimited keys in the V-Play Free Plan and as a V-Play customer.

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

See also V-Play License.


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

This QML property was introduced in V-Play 2.8.0.


read-onlyportrait : 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.


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, toolBar or statusBar is used.

This QML property was introduced in V-Play 2.8.0.

See also screenWidth and setScreenSize.


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, toolBar or statusBar is used.

This QML property was introduced in V-Play 2.8.0.

See also screenHeight and setScreenSize.


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 VPlayApps 1.0
import QtQuick 2.5

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 How to Make a Multi Language App or Game with V-Play.

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

      import VPlayApps 1.0
      import QtQuick 2.5

      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 VPlayApps 1.0
     import QtQuick 2.5

     App {

        Component.onCompleted: {

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

This QML property was introduced in V-Play 2.10.1.

See also Storage.


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 QML property was introduced in V-Play 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.


read-onlytablet : bool

This read-only property gets true if the screen's diameter is bigger than 5.3 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.


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 VPlayApps 1.0

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 QML property was introduced in V-Play 2.10.0.


read-onlywidthInInches : 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

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.

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.

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.


splashScreenFinished()

This handler gets called when the V-Play 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 V-Play Starter License or if you did not set any licenseKey. Upgrade to one of the other licenses to hide the splash screen.


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 VPlayApps 1.0
import QtQuick 2.0

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 V-Play.

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 V-Play to choose the default V-Play 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


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 QML method was introduced in V-Play 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 VPlayApps 1.0
import QtQuick 2.0

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 V-Play.

See also dp(), dpScale, and uiScale.


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
Sign up for Free and start developing right away!
I want to make Games
I want to make Apps
Game Development
Cross-Platform, Any Resolution

Use one IDE to deploy to all supported platforms, including iOS and Android, from a single code base.

Support all screen resolutions, aspect ratios and sizes with auto-adapting UI elements, smart scene scaling and memory efficient asset selection.

Learn More

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Multiplayer

V-Play Multiplayer supports both real-time and turn-based gameplay, so you can use it to make many different types of cross-platform multiplayer games. It's perfect for making player-vs-player games like 'Words with Friends' or games for a large amount of players, such as 'Clash of Clans'.

Learn More Video

Highscores & Achievements

The V-Play Game Network is a cross-platform gaming service that allows players around the world to compare game highscores and achievements. Players can also challenge each other across multiple platforms and share their progress on Facebook.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code.

import QtQuick 2.0
import VPlay 2.0

GameWindow {
  Scene {
    
    SimpleButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Level Editor

The LevelEditor can be used during development to create and modify levels for your game, which you can then bundle in your final publishing build. Additionally, you can also integrate the in-game level editor to your published game and let your gamers create new levels.

Learn More Video

Card Game like UNO, Hearthstone or Poker

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/OneCard/OneCard.pro

Match-3 like Candy Crush Saga

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquash/JuicySquash.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/JuicySquashAdvanced/JuicySquashAdvanced.pro

Puzzle like 2048 or Threes!

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/2048/2048.pro

Casino like Big Win Slots

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlaskOfRum/FlaskOfRum.pro

Side Scroller like Jetpack Joyride or Flappy Bird

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/FlappyBird/FlappyBird.pro

Tower Defense like Castle Defense or Bloons TD

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Squaby/Squaby.pro

Falldown & Jump like Doodle Jump or Mega Jump

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak/ChickenOutbreak.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/ChickenOutbreak2/ChickenOutbreak2.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/DoodleJump/DoodleJump.pro

Platformer like Super Mario or Lep's World

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/Platformer/Platformer.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Action like Angry Birds, Fruit Ninja, Cut the Rope

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/BalloonPop/BalloonPop.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/CarChallenge/CarChallenge.pro

Arcade like Arkanoid or Space Invaders

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/demos/ZombieBreak/ZombieBreak.pro

Community like Super Mario Maker or Minecraft

We got a demo game for you!

The V-Play SDK includes an open-source demo for this game genre. You can use its source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/examples/Squaby/Squaby.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/StackTheBoxWithCommunityEditor/StackTheBoxWithCommunityEditor.pro

<Path to V-PlaySDK>/Examples/V-Play/demos/PlatformerWithLevelEditor/PlatformerWithLevelEditor.pro

Any other Idea? let us know how we can help you

You are looking for another demo?

The V-Play SDK includes many open-source demos for different game genres. You can use their source code and build your game in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

If you do not find your game genre in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us

App Development
Better Apps, Less Effort

Develop feature-rich, cross-platform mobile apps from a single code base.

V-Play apps look, feel and perform exactly like native iOS, Android and Desktop apps. With less code & much faster development time.

Learn More Highlights Video

V-Play ranked #1 at research2guidance cross-platform tool benchmarking 2014 by 2188 developers comparing 40 leading tools.

Save Time, Code & Money

Save up to 90% source code with V-Play, compared to frameworks like Xamarin, Titanium, React Native and others.

Learn More

QML & JavaScript

Qt Meta Language is a highly intuitive reactive language, which is super easy to learn, yet it's extremely powerful and flexible. Mix it with JavaScript to create awesome stuff, with just a few lines of code. QML also allows you to easily create smooth and complex animations.

import QtQuick 2.0
import VPlayApps 2.0

App {
  Page {
    
    AppButton {
      anchors.centerIn: parent
      text: "Press Me"
      onClicked: {
        console.debug("Wow you pressed me!")
      }
    }
  }
}

Learn More

Monetize & Analyze

With V-Play, you can use many 3rd party services for ads, in-app purchases, analytics and more, with just a few lines of code. All of these plugins work cross-platform, which allows you to maintain a single code base.

Learn More

Native Sensors & More

V-Play Apps harness the power of Qt, the leading cross-platform development framework used by over 1,000,000 developers.

This gives your access to native device features like sensors, camera, file system as well as multimedia, networking, localization and much more.

Learn More

Responsive Design

V-Play has built in responsive design capabilities, you can target phones and tablets with the same source code.

Learn More

Highly Extensible

You have existing JavaScript, C++ or native code? You want to add any 3rd party SDK that we do not offer already?

No worries, you can add any JS, C++, Java or Objective-C code to your project.

Learn More

Component Showcase App shows the most important V-Play features and components

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/showcase/Showcase.pro

Qt World Summit Conference App a full-featured conference management app made by V-Play

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/qtws2016/QtWS2016.pro

Twitter App how to build layouts like in the official Twitter app for iOS and Android

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/twitter/Twitter.pro

Maps App displays free bikes or boxes at bike stations for Vienna's bike sharing service Citybike Wien

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/maps/Maps.pro

Messaging App demonstrates how to create the UI of a Facebook Messenger like app

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/messaging/Messaging.pro

Weather App how to include powerful animations into your user interface

We got a demo app for you!

The V-Play SDK includes an open-source demo for this app type. You can use its source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play.

<Path to V-PlaySDK>/Examples/V-Play/appdemos/waether/Weather.pro

Any other Idea? let us know how we can help you

You are looking for another app demo?

The V-Play SDK includes many open-source demos for different app types. You can use their source code and build your app in record time. After installing V-Play, you can simply open the .pro file with Qt Creator, the development environment used for V-Play..

If you do not find your app type in this list and wonder if V-Play is the right choice, just contact us, we are happy to help!

Contact Us