Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to have single app for Phone and Tablet
Forum Updated to NodeBB v4.3 + New Features

How to have single app for Phone and Tablet

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 2.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marek
    wrote on last edited by A Former User
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marek
        wrote on last edited by Marek
        #3

        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

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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 :-)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marek
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @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)?

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Marek
                wrote on last edited by
                #7

                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."

                1 Reply Last reply
                0
                • Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @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...

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Marek
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved