Compilation of the "Golang-gui Development" project

Source: Internet
Author: User

In the previous article, we talked about installing THERECIPE/QT (https://www.cnblogs.com/apocelipes/p/9296754.html), and now let's talk about compiling a project that uses THERECIPE/QT.

THERECIPE/QT hereinafter referred to as QT, and Qt to distinguish.

Why can't I just use go build

Because QT uses MOC technology (meta-object compiler), for some QT extension syntax requires additional processing, the reader of the QT project in C + + should know that it is not possible to compile the project code directly with g++ or other compilers, but to build it through the makefile generated by Qmake. In this makefile file, the MOC program is used to handle the extended syntax of Q_object, which is then compiled by the C + + compiler after processing is complete. Golang is also the same process, just do not have to configure the Qmake, but with a qtdeploy command to complete the project's compilation.

Compile

Compiling is simple and a command is done:

Qtdeploy build [target] [Path/to/your/project]

Target is the target platform specified, and the compiled program will be able to run on the platform specified by target.

If you can also set target to Desktop,qtdeploy, the corresponding target will be selected based on the local environment. The following are some of the available target options:

    • Desktop
    • Windows
    • Linux
    • Android
    • Android-emulator
    • Ios
    • Ios-simulator
    • Sailfish
    • Sailfish-emulator
    • Rpi1
    • Rpi2
    • Rpi3

Of course, your project needs to be in $gopath:-P.

Qtdeploy will automatically call QTRCC and Qtmoc to precompile and then compile with go build, and all operations are done in this command. Let's look at an example below.

This is an example of using Qsplitter, the project structure is as follows:

tree splittersplitter/└──splitter.go

There is a splitter.go in the project directory This is our sample program,

Package Mainimport ("OS"        "Github.com/therecipe/qt/core"    "github.com/therecipe/qt/widgets") Func Main () {widgets. Newqapplication (len (OS). Args), OS. Args)//Left SiderSplitterleft: =widgets. NewQSplitter2 (core. Qt__horizontal, nil) Texttop:= Widgets. NewQTextEdit2 ("left Text", Splitterleft) splitterleft.addwidget (texttop)//Right SiderSplitterright: =widgets. NewQSplitter2 (core. Qt__vertical, Splitterleft) Textright:= Widgets. NewQTextEdit2 ("Right Text", Splitterright) Textbuttom:= Widgets. NewQTextEdit2 ("Lower Text", Splitterleft) splitterright.addwidget (textright) splitterright.addwidget (textbuttom) splitterLeft.SetWi Ndowtitle ("Splitter") Splitterleft.show () widgets. Qapplication_exec ()}

Specific code I will explain later, now we compile

Qtdeploy Build Desktop Splitter

Compiling will take a long time, my development environment is Linux, the project structure after compiling is as follows:

3

Splitter/├──deploy│└──linux│ ├──lib│ ├──plugins│ ├──qml│ ├──splitter│ └──splitter. SH ├──linux└──splitter.go

We can see that our program is generated in the Deploy directory, because our program does not use QT extension syntax for the time being, so there is no intermediate code generated by QTMOC.

Explain the files and directories in Deploy/linux,

LIB,PLUGINS,QML: These are the programs that need to be run, you need to pack them later, or the program cannot find the library does not work properly.

Splitter: Compiled generated by our sample program, the name is the name of our project directory.

Splitter.sh: Add the previous LIB,PLUGINS,QML to the environment variables such as Ld_library_path,qt_plugin_path= $dirname, Qml_import_path, and then run the program.

Perhaps you will think that splitter.sh is superfluous, in fact, the first program in the compilation after the game can be run without the help of the script directly, because it links the local library and dependencies, but in the environment outside the development machine installed your program or your program contains some resource files, it is likely that the target machine does not exist the corresponding library , and does not happen to have the resource file you need, this time using a script to run the program, it will be added to the environment variables in the scripting directory to find dependent libraries and resources, so that the program can run normally.

Therefore, it is recommended to run the program via [projectname].sh file ].

Of course, this script will be a little bit of a hassle when it comes to packaging deb/rpm, and I'll do a little makeover to solve the problem when the next introduction to the project is packaged:-P.

Then run the program:

CD splitter/deploy/Linuxbash splitter. SH

OK, have a good time.

For further instructions on Qtdeploy and other commands, please visit: Https://github.com/therecipe/qt/wiki/Available-Tools#qtdeploy

If you have any questions or suggestions, please note!

Related Article

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.