I need to lock the screen to a specific orientation for an android app that I'm making. is there a way to do that in QML? Google didn't get me any answers.
I am using Qt 5.2.
You can basically use the Screen.orientation
property for reading only. See the following example for details:
http://qt-project.org/doc/qt-5/qtquick-window-screeninfo-qml.html
The proper way as of today is to use the Android manifest file for this as done by the Qt Android developer at Digia for his QtHangMan game which is:
<activity android:screenOrientation="portrait" ...
The way to do this is-
<path to qt installation>/android_armv7/src/android/templates/AndroidManifest.xml
In the qmake file (*.pro) of your project, add the following line -
ANDROID_PACKAGE_SOURCE_DIR = <path to your templates directory>
#in case you added the directory one above the source directory, path to your templates directory = "../templates"
Build and Run. You should now see that the Orientation is fixed to whatever you have specified in the custom AndroidManifest.xml file
To understand what really is happening - here's the qt reference , look for ANDROID_PACKAGE_SOURCE_DIR
In case the link doesn't work in future, here's the relevant bits -
"ANDROID_PACKAGE_SOURCE_DIR: This variable can be used to specify a directory where additions and modifications can be made to the default Android package template. The androiddeployqt tool will copy the application template from Qt into the build directory, and then it will copy the contents of the ANDROID_PACKAGE_SOURCE_DIR on top of this, overwriting any existing files. The update step where parts of the source files are modified automatically to reflect your other settings is then run on the resulting merged package. If you, for instance, want to make a custom AndroidManifest.xml for your application, then place this directly into the folder specified in this variable. You can also add custom Java files in ANDROID_PACKAGE_SOURCE_DIR/src."
QtCreator - 4.2.1, Qt - 5.8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.