Qt for Android Development Summary, qtforandroid Development
Recently, I used Qt5.3.0 to develop Android applications. Due to a small amount of official information, I recorded problems encountered during the development process and solutions.
1. Only qml MediaPlayer can be used for video playback on the Android platform.
2. file: // For example:
Image{ source: "file:///mnt/usbhost1/Config/logo.png" }
3. Interaction between C ++ and qml js Methods
QQuickView view; view. setSource (QUrl (QStringLiteral ("qrc: // qml/MainView. qml "); QObject * qmlObj = (QObject *) view. rootObject (); MainWnd * w = new MainWnd (object );
// Expose the C ++ class to qml for calling. The alias is mainWndClassview. engine ()-> rootContext ()-> setContextProperty (QLatin1String ("mainWndClass"), w); // c ++ call the js method in qml // The parameter must be converted to QVariantQMetaObject:: invokeMethod (qmlObj, "showRight", Q_ARG (QVariant, 1); // call the subitem's js method qmlPlayer = qmlObj-> findChild <QObject *> ("playerArea "); QMetaObject: invokeMethod (qmlPlayer, "setVideoFile", Q_ARG (QVariant, currentVideoFile ));
// MainView. qmlRectangle {anchors. fill: parent property int leftAreaWidth: this. width/5*4 property int rightAreaWidth: this. width/5 property int queueFontSize function showRight (isShow ){....} player {id: playerArea // set objectName, which can be found in c ++: objectName: "playerArea" width: parent. width height: parent. height }}
4. c ++ calls java Android api
Create the \ android \ src \ org \ rophie \ ProjectName \ JavaClass. java directory under the project directory
Org \ rophie \ ProjectName is the package name of the java class org. rophie. ProjectName;
For example, I call the Android API to adjust the system volume.
Package org. rophie. projectName; import org. qtproject. qt5.android. bindings. qtActivity; import android. widget. toast; import android. media. audioManager; import android. content. context; public class JavaClass extends QtActivity {private static JavaClass m_instance; private static AudioManager mAudioManager; public JavaClass () {// The constructor must be m_instance = this ;} public static void setVolume (int vol) {if (mAudioManager = null) {mAudioManager = (AudioManager) m_instance.getSystemService (Context. AUDIO_SERVICE);} mAudioManager. setStreamVolume (AudioManager. STREAM_MUSIC, vol, 0 );}}
C ++ call
QAndroidJniObject: callStaticMethod <void> ("org/rophie/ProjectName/JavaClass", "setVolume", "(I) V", 3); // For details, refer to the QAndroidJniObject class
5. BroadcastReceiver enables Automatic startup, which is exactly the same as Android
Public void onReceive (Context context, Intent intent ){...... // JavaClass is the java main class Intent intent2 that inherits QtActivity = new Intent (context, JavaClass. class );......}
6. Call a third-party jar package, create a directory libs under the src directory at the same level, and import. jar packages to use
Can android applications be developed using java on the QT platform? What is QT for Android?
First question
Can android applications be developed using java on the QT platform?
Currently, this is not acceptable!
Second question
What does QT for Android mean?
QT for Android is an SDK. Programmers familiar with Qt can use it and generate an APK that can be run directly on the android platform. However, it is not yet mature and is still being improved.
In the environment configuration of QT for android linux, The necessitas package has been downloaded. How can I compile the QT program into an android program using commands?
Although many people use Redhat or Fedora as the host computer operating system on the network, I think Ubuntu is the most convenient, because most of the required software packages can be installed through apt-get, instead of compiling the source code.
Although many people use Redhat or Fedora as the host computer operating system on the network, I think Ubuntu is the most convenient, because most of the required software packages can be installed through apt-get, instead of compiling the source code. It is not easy to compile the source code by yourself, because unexpected and inexplicable errors often occur during the compilation process.
The operating system we use is Ubuntu 8.04, and the latest version of QT 4.4.0 is simple to install. You only need to edit the command and run the following command:
Sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos
Note that in this version of the software package, the qt4-dev-tools contains tools such as Qt Assistant and Qt Linguist, so you do not need to install them separately. Others, qt4-doc is a help document that contains detailed descriptions of various class libraries in Qt and a wide range of example programs that can be opened using Qt Assistant tools. The qt4-qtconfig is a dialog box for configuring the Qt environment, which is usually the default and is rarely necessary to change. The qt4-demos contains many executable files and source code that can run. A qt4-designer is a designer used to design a GUI.
To connect to the MySQL database, install the MySQL DRIVER:
Sudo apt-get install libqt4-sql-mysql
It is much easier to install and configure the Qt MySQL driver in Windows. If you need other Qt libraries that are not installed by default, you can enter sudo apt-get install libqt4 in the command line and press the tab key to automatically complete the installation, all software packages starting with libqt4-are listed, as shown in:
You can use a command to complete these operations without compiling the source code. It is a practical tips to use the tab key to list all optional software packages without knowing the name.
In my project, I also need to draw some data curves and statistical charts, which are provided by a third-party QWT library. Similarly, you only need one command to complete the installation:
Sudo apt-get install libqwt5-qt4 libqwt5-qt4-dev
Open Qt Designer and you will find that the "Qwt widgets" group is added to the left Widget list.
Finally, I think QDevelop is very good about the integrated development environment. It works well with Qt Designer and has the function of prompting class member functions. Run the following command to install:
Sudo apt-get install qdevelop
In this way, you can use Qdevelop to write code, compile and debug, and use Qt Designer to design the interface, which is highly efficient in development.