Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the Ubuntu SDK to develop a QML app that runs both on the desktop and on mobile devices. Depending on where it's running on the desktop or on a device, certain behaviours should be different.

What's the recommended way of programmatically detecting whether an app is running on the desktop or on a mobile device?

share|improve this question
I think it can be done by checking proess status – Tachyons Jun 11 '13 at 10:17
up vote 2 down vote accepted

At the moment the only way to detect it is by checking the Application's width and height. For instance assuming that the phone's widthxheight is 40x71 GU (default portrait), the tablet is 160x100 GU (default landscape), anything that goes above 160x100 GU can be considered as desktop.

There are plans to provide flags to identify for instance whether there is a HW keyboard attached, pointing device, ASO, however those flags should not be used alone to identify a desktop form factor as you can attach mouse/HW keyboard to phone/tablet through bluetooth.

share|improve this answer
Thanks! I've also now come to realize another important bit of information: you can set a fixed window size for the desktop, on the phone it automatically opens full-screen – David Planella Jun 14 '13 at 10:51

@zsombi so something like this?

MainView {
    id: mainView
    objectName: "mainView"
    applicationName: "myapp"
    automaticOrientation: true

    //detect whether an app is running on a mobile device or on the desktop, base on screen-size
    property bool desktop: false;
    function sizeChanged()
        if(mainView.width > && mainView.height <
           desktop = true;
            desktop = false;
    onWidthChanged: {
    onHeightChanged: {

Then you can make an

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.