Migration and deployment of QT program in Windows Mobile

Source: Internet
Author: User
Tags i18n
Prepare the Visual Studio Environment

The Windows Mobile Development Environment used in this article is Visual Studio 2008. You must select the installation method when installing vs2008.Visual c ++And selectSmart device Programmable Technology. For example:

If you have already installed vs2008, you only need to find visualstudio2008 from "Add/delete programs" in windows and enter maintenance mode to add or delete vs2008 components.

After installing vs2008, you can develop an application based on windowslele5.0. However, most Windows Mobile phones are already in windowsmobile6.0 or later versions, and many mobile phone players have even converted their phones into windowsmobile6.5. We recommend that you install at least one SDK for Windows Mobile 6. And it is best to install a Simplified Chinese version, because Windows Mobile in the device simulator in the Simplified Chinese version is a Chinese version. If the English version of the device simulator is used, after the program is run, only the Chinese characters are displayed as boxes.□□□□□. (Windows Mobile development resources list: http://www.cnblogs.com/upto/archive/2007/03/13/mobile-development-tools.html)

After the Windows Mobile SDK is installed, do not worry about the subsequent steps to install the QT library. Let's create a Windows Mobile program first:

(Click to view the big picture)

 

Directly press F5 to debug the project. After a short compilation and deployment step, you can see a device Simulator Interface and run our test program randomly, such:

If it is running on an English Rom, the above picture will appear, you can refer to the modification to select a suitable Simulator for debugging (click the thumbnail to see the big picture ):

 

Install the QT library for Windows Mobile

You can refer to the official website of QT for specific installation steps, specific visit: http://doc.trolltech.com/4.5/install-wince.html

I will briefly introduce how to install the QT library for vs2008 + windowsmobile SDK 6 step by step according to the above instructions.

Step 1: Download QT.

The latest version of QT for Open Source C ++ development on Windows CE is 4.5.2. You can download it from the following link:

Http://get.qtsoftware.com/qt/source/qt-embedded-wince-opensource-src-4.5.2.zip

To download the latest version, visit this URL:

Http://www.qtsoftware.com/downloads/win-ce-cpp

Well, the package size is 138 m. I used ADSL for a while ....

Step 2: configure the settings before installation

The first is to unpackage, the downloaded package decompress to c: \ QT, but the directory name qt-embedded-wince-opensource-src-4.5.2 is long, modified to c: \ QT \ ce452.

We can note that there is an important batch processing command setcepaths. BAT in c: \ QT \ ce452 \ bin.

Next, from the menu item in Visual Studio 2008, find the Visual Studio 2008 command prompt in tool alt studio. Click it to open a command prompt. In this command prompt, various environment variables required by Visual Studio have been set. You can also open any command prompt and run c: \ Program Files \ Microsoft Visual Studio 9.0 \ Vc \ vcvarsall. bat.

Then, add c: \ QT \ ce452 \ bin to the path environment variable.

Note: Starting from this step, we will mainly input commands in this Command Prompt window.

Step 3: configure the QT Library
We can see the following configuration example on the official QT Website:
configure -platform win32-msvc2005 -xplatform wincewm50pocket-msvc2005

But we use vs2008. How can we configure it? We can open the c: \ QT \ ce452 \ bin \ setcepaths mentioned earlier (Note: Open it in a text editor instead of running it. bat, at the end of the page you see the platform name for vs2008: wincewm60professional-msvc2008 (for PPC type terminals, if it is not a touch of smartphone then select wincewm60standard-msvc2008), the two names can also be in C: \ QT \ ce452 \ mkspecs directory.

Then we execute the following command:

CD/d c: \ QT \ ce452

Configure-platform win32-msvc2008-xplatform wincewm60professional-msvc2008

So after a long wait, I finally correctly configured the QT library.

The next step is a very important operation. Run:

Setcepaths wincewm60professional-msvc2008

This command will set appropriate environment variables such as path, include, and Lib for us, so that we can correctly reference the code including files and library files during the compilation process.

Then, the QT library is compiled using the Command provided by vs2008. Enter the following in the command line:

Nmake

This time will go through a longer compilation process. But if nothing happens. You just need to take a walk or have a cup of coffee for a while and then come back. The QT for Windows Mobile 6 library has been compiled and can be used.

Port and run applications developed by QT

Note that we still perform subsequent operations at the previous command prompt. If you have closed the prompt window, you can open a new Prompt window and add c: \ QT \ ce452 \ bin to the beginning of the PATH environment variable, then run vcvarsall of Visual Studio. bat, as shown below:

Path c: \ QT \ ce452 \ bin \; % PATH %

"C: \ Program Files \ Microsoft Visual Studio 9.0 \ Vc \ vcvarsall. Bat"

Setcepaths wincewm60professional-msvc2008

The environment variable setting here is a very important step. You can generate and compile the Windows Mobile Application Project correctly only after correct settings.

First, generate the *. vcproj file that can be used in vs2008 according to the *. Pro file of QT. If you are developing in the vs2008 + QT integrated environment, you can useQmake-ProjectCommand to generate the *. Pro file. Then we can use the following command to generate the vcproj file:

Qmake-TP VC

You can also specify the output file:

Qmake-tp vc-O ***. vcproj

If you have used Visual Studio and QT to develop desktop applications, you will surely find that this command is actually used to convert the QT project file ***. pro to the Visual Studio project file.

Note: If you have not set any environment variables, it is best to run qmake using the absolute path, for exampleC: \ QT \ ce452 \ bin \ qmake-tp vc-O ***. vcproj

Use visualstudio2008 to open the generated vcproj file and press F5 to compile and run it. For most simple QT applications, there won't be too many problems in this step. However, there are some differences between the QT library used in WindowsCE and the QT library used in common Windows platforms. The specific difference is, well, I can't really tell a beginner. However, when I perform a specific porting job, I have encountered at least qstring: tostdstring () which cannot be used for Windows Mobile development. It is said that STL is not supported in Windows Mobile ....

Well, after some modifications, our new project can finally be compiled successfully. Then press F5 to run it.

Generate .... OK

Deploy .... OK

Load the application .... Yeah, our QT window is successfully displayed in the simulator system:

The contrast image is running in Windows 7. Is it very similar? Well, there is a little difference. fonts and buttons are different from those on the desktop. The biggest difference is that the menu bar of the window is in the lower right corner.

This test program is used to test the dynamic switching language. In the desktop environment, if you click translate in the menu, the text in the window is translated into Chinese or another string. The response code of the menu is as follows:

Void i18n: on_actiontranslate_triggered ()
{
Qtranslator trans;
Switch (nlang)
{
Case 0:
Trans. Load ("i18n_zh ");
Break;
Case 1:
// Nothing
Break;
}
Qapp-> installtranslator (& trans );
Nlang = (nlang + 1) % 2;
Ui. retranslateui (this );
}

However, after clicking the menu on the simulator, there is no response on the interface. Check the above Code. Obviously, trans. Load will definitely fail... When we directly compile the program, Visual Studio simply deploys the application main output file (i18n.exe) and corresponding QT library functions and Visual Studio 2008 C Runtime Library. In addition, careful friends will also note that the current startup is an English version simulator, if we do not change it to a Chinese simulator, even if we have successfully deployed i18n_zh.qm, it will not display Chinese. So let's change the deployment settings from Visual Studio:

You can select "Project Properties" from the "project" menu to open the above window, and then select "deployment" from the left. The "deployment device" lists all installed and registered simulators on your machine. If you have installed the developer tool of Windows Mobile 6.5, you can also see the option of Windows Mobile 6.5. In the "additional file", there are some files to be deployed along with the target file. The qtgui and qtcore libraries and the runtime libraries of visualstudio2008 are configured and deployed here to the simulator. Let's open it:

The list of additional files to be deployed is in the format of one file per row. The format of each line isFile Name | Local disk directory | target path | Registry NoIn, I have filled in the deployment information of the missing i18n_zh.qm file.

After confirmation, press F5 to start running again. This is a Chinese simulator, and the Chinese after the Display language is switched is displayed correctly:

Windows written in QT can be dragged and changed in the lower right corner of Windows Mobile Phones. You can also hold down the title bar and drag it to change the position of the window, they are exactly the same as normal Windows! Do you really want to start your windowsmobile journey right away? Don't worry. The last step is to deploy the QT program on Windows Mobile!

Deployment of QT program on Windows Mobile

At this time, your program has been running normally on the Windows Mobile simulator, and you must be the same as me, very eager to let your program run on the Windows Mobile Phone!

With the help of Visual Studio 2008, it is easy.

First, we can add a new installation and deployment project in the solution where our QT project is located, for example (click to see the big picture ):

There are several key points:

  1. Add to current solution (because the project to be installed and deployed depends on our main project)
  2. Project name. It is best not to include Chinese characters or spaces in the directory.
  3. In the properties of the installation and deployment project, the manufacture Name of the manufacturer cannot be in Chinese. You must change the default company name to English. Otherwise, the system fails to generate the cab file.

Shows the added Visual Studio interface.

By default, the "Program Files folder" and "application folder" items are displayed in the "File System" tab, which may be confusing to you, however, a simple experiment can understand what each means. Here is a brief description:

The location program files corresponds to the "program" on Windows Mobile. You can create a shortcut for the target file here, so that your program icons can be displayed on your mobile phone. If you do not create a shortcut here and want to run your software, you can only search for your program through the Windows Mobile File Manager to run it. This location means a little bit of PC "desktop.
In addition, you can add a "Start Menu" system folder, which corresponds to the Start menu in the upper left corner of the Windows Mobile phone. This is consistent with the Windows version on the desktop.

The location "application folder" is actually equivalent to c: \ Program Files \… in windows \.... So when you add the file to be deployed, you should naturally add it to the "Application folder. Add the files to be deployed as follows:

The added image:

 

 

 

Note: I am adding a release file. If you want to package the debug version program, the files to be added should be qtcored4.dllqtguid4. dll and msvcr90d. dll.

After adding the package, switch the project configuration to release, right-click the installation project, and select "generate" to create the cab package that can be installed on your mobile phone.

So far. Success! We can finally run our own programs on our windows mobile phone. Let's take a look at the created installation package:

Success !!!! Orz...

A software with no functionality actually has a size of nearly 9 MB. It seems that the program using QT cannot take a slim route ~~~~~ It's a weakness in the United States ....

Now it is said that Nokia will deploy the QT library on all its later mobile phones, and it does not know whether it is true or false. If it is true, then I will write another blog article about migrating the QT program under symbianos. Haha!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.