How to have single app for Phone and Tablet



  • Hi all

    Let's say I have QML app and I want to have single project (common source code) that will build application that is running well on Phone and Tablet with different UI and different functions.
    In fact I have now QtWidget app (that I want to rewrite to QML) that has single source code but when I change one #defined app_type I can generate binary for three platforms. There are some "#ifdef" in the code which for example load different UI, or change available functionality. But the problem is that I end up with two binaries for AppStore (iPhone and iPad) and two binaries for GooglePlay (Phone and Tablet) which creates problems with different boundleId when I'm using services like Push Notifications.
    So I would like to have single App output for Tablet and Phone, but when app is starting I need to load different main.qml and also change some functionality. I can't simply check that when width is more than height then I'm running on iPad because my app on Phone is locked in Landscape orientation.
    So how to check during app startup (preferably in main.cpp) that I'm running on Tablet or Phone ?

    Best Regards
    Marek


  • Moderators

    Hi! You could use the stuff provided by QScreen to get the pixel size, physical size and primary orientation of the device and then decide which of your GUI files fits best.



  • primary orientation would be good I think, but what can I deduce from pixel size ?
    Is there something like best practice way or something like that, I mean surely I'm not the only one with this problem ?

    docs says that primaryOrientation : const Qt::ScreenOrientation may change when display is rotated, so not good.
    however, nativeOrientation : const Qt::ScreenOrientation is a property of hardware and does not change


  • Moderators

    Oh right, I meant nativeOrientation, not primaryOrientation. Mixed that up. Regarding physical screen size, resolution an such: I thought this might be of interest to you, too. E.g. there are devices that are sold as tablets but that are really small and also phones that are really big. But I don't do mobile development, so better wait for an answer of an expert :-)



  • Yeah some phones have quite large screens but not as big as tablets. Maybe assuming some physical size like more than 6 inch is tablet and below phone?



  • @Marek said in how to have single app for Phone and Tablet:

    with different UI and different functions.

    Will be the functions different based on screen size or in hardware functionality (i.e. phone or not phone -> tablet)?



  • Hi

    Sorry for late reply. Functionality is different based on screen size actually, UI displayed on tablet won't fit into phone screen. I have read some info on google and I think I need to calculate physical size of the screen and everything below 6,5" treat as phone, everything bigger than 6,5" - tablet. Example below is from Android, need something similar in Qt

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    
    float yInches= metrics.heightPixels/metrics.ydpi;
    float xInches= metrics.widthPixels/metrics.xdpi;
    double diagonalInches = Math.sqrt(xInches*xInches + yInches*yInches);
    if (diagonalInches>=6.5){
        // 6.5inch device or bigger
    }else{
        // smaller device
    }
    

    I wonder whether I can trust physicalSize : const QSizeF from QScreen, docs says:
    "Depending on what information the underlying system provides the value might not be entirely accurate."



  • @Marek said in How to have single app for Phone and Tablet:

    I wonder whether I can trust physicalSize : const QSizeF from QScreen

    What if in addition to that you have a screen size validation option in your application settings?, so the user can pick the 4 corners and you can have another value to compare with.
    I remember calibrating the screen of my Dell X5 Axim PDA back in 2003...



  • I need some solution working out of the box and screen calibration as an option.... rather not.
    physical size of the screen would be nice if it can be trusted.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.