由于种种原因,放弃了therecipe/qt,转向了更为轻量级的qamel,这个库的安装非常简单,跟随着以下步骤就能解决

安装

安装qamel非常简单,只需要go get -v github.com/go-qamel/qamel即可。如果一切顺利,将会自动编译出qamel工具并放置在$GOPATH/bin中。

如果由于网络原因安装失败,你也可以选择手动编译安装qamel工具

首先clone项目到任意文件夹中git clone https://github.com/go-qamel/qamel.git,完成之后进入文件夹中的cmd目录并用go mod进行初始化。这是为了避免网络原因下载第三方包速度过慢。初始之后就可以直接进行go build -o qamel进行编译,一切正常之后将qamel放进$PATH中。

设置

qamel和therecipe/qt一样,在使用之前需要设置环境变量和一些其他的东西,按照官方wiki的说法首先需要qamel profile setup设置,qamel的设置非常人性化,每一步都有详细的介绍,如实填写即可。

$ qamel profile setup

Thanks for using qamel, QML's binding for Go.

Please specify the target OS for this profile. Possible values are "windows", "linux" and "darwin".

Keep it empty to use your system OS.

// 选择操作系统

Target OS (default windows) : linux

Please specify the target architecture for this profile. Possible values are "386" and "amd64".

Keep it empty to use your system architecture.

// 选择系统架构,amd64指64位系统

Target arch (default amd64) : amd64

Please specify whether this profile used to build static or shared app.

// 选择今后编译生成的软件类型,本地还是可分享

Use static mode (y/n, default n) : n

Please specify the *full path* to your Qt's tools directory.

This might be different depending on your platform or your target. For example, in Linux with Qt 5.11.1, the tools are located in $HOME/Qt5.11.1/5.11.1/gcc_64/bin/

// 输入qt环境变量

Qt tools dir : $HOME/Qt5.13.0/5.13.0/gcc_64/bin/

qmake : found

moc : found

rcc : found

Please specify the *full path* to your compiler.

Keep it empty to use the default compiler on your system.

// 确认路径是否正确,正确则直接回车,不正确修改路径

C compiler (default gcc.exe) : C:\Qt\Qt5.12.0\Tools\mingw730_64\bin\gcc.exe

C++ compiler (default g++.exe) : C:\Qt\Qt5.12.0\Tools\mingw730_64\bin\g++.exe

Objdump (default objdump.exe) : C:\Qt\Qt5.12.0\Tools\mingw730_64\bin\objdump.exe

// 如果你是windows系统,还需要配置windres路径

Since you are targeting Windows, you might want to set icon for your executable file. To do so, please specify the *full path* to windres on your system. It's usually located in the directory where MinGW is installed.

Path to windres : C:\Qt\Qt5.12.0\Tools\mingw730_64\bin\windres.exe

Generating some code for binding...done

Saving profile default...done

Setup finished.

Now you can get started on your own QML app.

到这qamel的安装配置就完成了,可以qamel profile print查看一下配置是否正确

编译

按照官方wiki,qamel支持交叉编译,但仅仅支持Linux和Windows。

Linux To Linux

qamel build (这里用的是上述的默认linux配置)

Linux To Windows

要在Linux编译Windows程序(默认64位)需要安装一个MXE插件

git clone https://github.com/mxe/mxe.git /home/radhi/MXE

cd /home/radhi/MXE

make MXE_TARGETS="x86_64-w64-mingw32.shared" cc Cairo harfbuzz qt5

然后再建立一个新的配置qamel profile setup win_64,在最后选择windres的时候选择MXE路径中的/usr/bin/x86_64-w64-mingw32.shared-windes即可

最后编译qamel build -p win_64

Docker

为了方便编译,qamel也提供了docker镜像,在拉取镜像之后就可以进行编译了。

如Linux编译Windows64位程序只需要拉取tag为win64即可,然后进行编译qamel locker build -p win64

要注意的是,官方docker中的qt版本是5.12,如果有新特性可能编译不能通过,而且中文环境输入有问题建议自行建立交叉编译环境

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐