How to lock screen orientation (Android&Qt5.1)



  • Is there any solution for locking screen orientation to portrait mode?

    Something equivalent to good old solution in main.cpp:

    @QmlApplicationViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);@



  • 1 solution would be the android manifest.

    just add android:screenOrientation="portrait" for the main activity



  • could you, please, alter my manifest file below?

    @<?xml version='1.0' encoding='utf-8'?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" package="com.mycomp.exampleapp" android:versionCode="1">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtApplication">
    <activity android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden|navigation" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtActivity">
    <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <meta-data android:resource="@array/qt_sources" android:name="android.app.qt_sources_resource_id"/>
    <meta-data android:value="@string/repository" android:name="android.app.repository"/>
    <meta-data android:resource="@array/qt_libs" android:name="android.app.qt_libs_resource_id"/>
    <meta-data android:resource="@array/bundled_libs" android:name="android.app.bundled_libs_resource_id"/>
    <meta-data android:value="iqchallengesliderpro" android:name="android.app.lib_name"/>
    <!-- Deploy Qt libs as part of package -->
    <meta-data android:value="0" android:name="android.app.bundle_local_qt_libs"/>
    <meta-data android:resource="@array/bundled_in_lib" android:name="android.app.bundled_in_lib_resource_id"/>
    <meta-data android:resource="@array/bundled_in_assets" android:name="android.app.bundled_in_assets_resource_id"/>
    <!-- Run with local libs -->
    <meta-data android:value="1" android:name="android.app.use_local_qt_libs"/>
    <meta-data android:value="/data/local/tmp/qt/" android:name="android.app.libs_prefix"/>
    <meta-data android:value="libs/libgnustl_shared.so:lib/libQt5QuickParticles.so:plugins/platforms/android/libqtforandroidGL.so:" android:name="android.app.load_local_libs"/>
    <meta-data android:value="jar/QtAndroid.jar:" android:name="android.app.load_local_jars"/>
    <meta-data android:value=":" android:name="android.app.static_init_classes"/>
    <!-- Messages maps -->
    <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
    <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
    <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
    <!-- Messages maps -->
    <!-- Splash screen -->
    <meta-data android:resource="@layout/splash" android:name="android.app.splash_screen"/>
    <!-- Splash screen -->
    </activity>
    </application>
    <supports-screens android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" android:largeScreens="true"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    </manifest>@



  • @ <?xml version='1.0' encoding='utf-8'?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" package="com.mycomp.exampleapp" android:versionCode="1">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtApplication">
    <activity android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden|navigation" android:label="@string/app_name" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:screenOrientation="portrait">
    <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <meta-data android:resource="@array/qt_sources" android:name="android.app.qt_sources_resource_id"/>
    <meta-data android:value="@string/repository" android:name="android.app.repository"/>
    <meta-data android:resource="@array/qt_libs" android:name="android.app.qt_libs_resource_id"/>
    <meta-data android:resource="@array/bundled_libs" android:name="android.app.bundled_libs_resource_id"/>
    <meta-data android:value="iqchallengesliderpro" android:name="android.app.lib_name"/>
    <!-- Deploy Qt libs as part of package -->
    <meta-data android:value="0" android:name="android.app.bundle_local_qt_libs"/>
    <meta-data android:resource="@array/bundled_in_lib" android:name="android.app.bundled_in_lib_resource_id"/>
    <meta-data android:resource="@array/bundled_in_assets" android:name="android.app.bundled_in_assets_resource_id"/>
    <!-- Run with local libs -->
    <meta-data android:value="1" android:name="android.app.use_local_qt_libs"/>
    <meta-data android:value="/data/local/tmp/qt/" android:name="android.app.libs_prefix"/>
    <meta-data android:value="libs/libgnustl_shared.so:lib/libQt5QuickParticles.so:plugins/platforms/android/libqtforandroidGL.so:" android:name="android.app.load_local_libs"/>
    <meta-data android:value="jar/QtAndroid.jar:" android:name="android.app.load_local_jars"/>
    <meta-data android:value=":" android:name="android.app.static_init_classes"/>
    <!-- Messages maps -->
    <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
    <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
    <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
    <!-- Messages maps -->
    <!-- Splash screen -->
    <meta-data android:resource="@layout/splash" android:name="android.app.splash_screen"/>
    <!-- Splash screen -->
    </activity>
    </application>
    <supports-screens android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" android:largeScreens="true"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    </manifest>
    @



  • This worked for me too, thanks.
    Anyway it sounds strange to me that there is not something like:
    @Window.setOrientation@
    @Window.lockOrientation@
    @Screen.setOrientation@
    @Screen.lockOrientation@

    ps. I use qt 5.4 :)



  • This post is deleted!

Log in to reply
 

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