1. Copy the entire project folder created with QT Creator on the Windows platform to the Linux system, you can use a USB flash drive to copy or share folders ).
2. Modify the access permissions of all files in folders and folders. First, switch to the directory where the folder is located (under/home/exam), and then modify the access permission. The command is as follows:
Chmod-r 777 folder
Assume that my folder is named mainwindow. The command is: chmod-r 777 mainwindow.
For example:
After modifying the access permission, run the LS-l mainwindow command to view the attributes of the modified file.
3. Open QT creator, for example:
Click "open project..." to open the copied project mainwindow. For example:
After opening the project, open a header file or source file in the project. If an error message is displayed at the top of the Editor:
It indicates that the file contains characters that cannot be recognized by the editor. It is generally a Chinese character entered on the Windows platform. You will find that all Chinese characters in the file are garbled. In this case, the editor cannot modify the file content. This is because the default encoding used by the two systems is different. In this case, click "select encoding" in the error prompt (or click "select encoding" under "edit") to bring up a text encoding dialog box, for example:
Select "gb2312" and click "reload with encoding" to reload the file according to the encoding. The Chinese characters in the file are displayed.
If the pop-up text encoding dialog box does not contain "gb2312", it means that QT Creator does not load the relevant DLL file by default (the extension name is. So in Linux). The solution is as follows:
Step 1: Open the path according to the installation directory of QT creator
"Qtsdk \ Desktop \ QT \ 473 \ GCC \ plugins" found a "codecs" folder with four files under it, such:
The path is in the red box, and the green box contains the four encoding library files.
Step 2: copy the entire codecs folder to the "qtsdk \ qtcreator \ bin" directory. The copied folder is as follows:
The red box contains the path and the green box contains the copied folder.
Step 3: re-open QT creator, open a file, and select encoding under the "edit" menu... "," gb2312 "is displayed in the pop-up text encoding dialog box ".
4. Compile the program.
Because the compilation path configured on Windows is invalid in Linux, you must configure the project before compiling, for example:
Click the "Projects" button on the left to bring up the project configuration interface. You can select debug or release in the "Edit build configuration" section above, in the "build directory" below, select the new compilation path.
After the path is configured, You can debug and run the program, for example:
The running button is in the red box, And the debugging button is in the green box. click the button in the green box to start debugging. After debugging, the program runs normally, for example (my project is a text editor ):
At this time, we will find garbled characters in the program. The research finds that Chinese strings directly used in the program are not displayed.
The solution is to add the corresponding font in the main function, as shown below:
Add a header file # include <qtextcodec>, add two lines of code in the red box in the figure, and compile and run the program again, as shown below:
The program runs normally.