QT installation environment and cross-platform compilation of those things

 QT SDK and source code download

http://download.qt.io

 

QT5.13 installation

The windows typically use VS to develop, but under linux use OtCreator to develop.

 

linux, for example with Ubuntu

Before installing Qt need to install g ++ make

sudo apt-get install libgl1-mesa-dev

After installation environment is ready to be installed directly ./qt-opensource-linux-x64-5.13.0.run.

Note: typically installed in / usr, which a lot of folders, depending on the type of document, classify, not a software a folder. Before the old versions of Linux used to be placed under / usr / local directory.

On the part of the software / under opt, it is a unified software in a folder. / Opt directory specialized third-party software is used to place the file, such as some archive decompression software are placed here.

For example, "NetEase cloud music" to install in / usr / lib / netease-cloud-music

For example, Chrome will put / opt / google / chrome

 

Installation under Windows debugging tools set (using Microsoft's compiler)

After installing VisualStudio2017, then install win10 SDK, the installation is complete, the C: There is a cdb.exe for debugging \ Program Files (x86) Windows Kits Debuggers under \ \ 10 \ \ x64 (x86).

Under Windows, note that when the QT supports the use of configuration to QTCreator compiler and support VS compiler must be consistent. Here we use VS2017 and QT5.13.

After installation, open Kits interface view as follows. There may be no compiler configuration, you need to manually select it.

 

 

 

QTCreator project configuration

1 configuration library and header files

 

Then import the file header and the file path where lib, dll copied to the executable directory.

 

2, VS + QT project configuration

 

2.1, first install the QT plug-in, depending on the version of VS installed, used here qt-vsaddin-msvc2017-2.3.2

 

 

2.2, open VS, in QT VS menu bar Tools-> QT Options, configure your QT version

 

 

 

一 QT程序编译经历的步骤

 

1 qmake编译pro生成makefile

2 jom或者make编译makefile

 生产界面源码 uic.exe widget.ui –o ui_widget.h

 生产信号槽代码 moc.exe widget.h moc_widget.cpp

 

二 手动创建pro

windows下环境设置如下

 

linux下设置如下

 

先设置qmake的路径,然后使用qmake由testqmake.pro文件构建得到makefile文件。

然后使用make编译得到可执行文件。

 

三、将QtCreator创建的工程转换为VS

直接使用命令的行

 

使用命令行产生的代码在VS打开时,可能会出现“找不到 Windows SDK 版本8.1.请安装所需的版本的 Windows SDK 或者在项目属性页的问题解决方案”这种错误。处理方法如下所示。

 

 

或者使用插件也可以将QTCreator工程转换为VS工程。

 

 

 

四、pro文件下添加一个内部库

无论是通过UI,还是直接在pro文件中更改,都需要在添加之后,重新执行下qmake。

 

在帮助手册中找到你要使用的QT内部类,帮助手册会告诉你这个类该使用什么模块。

 

 

 

五、头文件引用。

对于工程来说,当前路径表示的是构建路径,即和源码同一级的文件夹下,如图是build-testqmake-Desktop_Qt_5_13_0_MSVC2017_64bit-Debug文件夹下。

 

$$PWD是获取当前源码路径,即在testqmake文件夹下,所以以下两个路径是相等的。

 

 

 

六、pro文件下 库引用和库路径指定。

语法: LIBS += -L”../../lib” –lopencv_world320 类似于链接库

虽然Windows和linux下库的名字稍有区别

linux下 libopencv_world320.so

windows下 opencv_world320.lib

但是QT会自动帮我们对应不同的平台。

 

pro文件下指定运行目录

DESTDIR  +=  ../../bin

 

pro文件下指定运行程序名字

TARGET = testq

 

七、QT创建一个动态库

pro文件下指定TEMPLATE = lib,如果pro文件下不指定,则默认生成应用程序。

linux下动态库是xxx.so 静态库是xxx.a

windows下动态库是xxx.dll 静态库是xxx.lib,而且动态库还包含一个标示地址的lib文件,而且,windows下还需要指定导出函数。

 

八、debug和release版本编译设置

CONFIG += debug_and_release(默认情况下是debug和release都有的)

除此之外,CONFIG还提供了CONFIG()函数。如下所示,如果是debug版本则输出的程序称为debug_binary,否在是release_binary。

CONFIG(debug, debug|release){//注意大括号必须紧跟着

TARGET = debug_binary

}else{

TARGET = release_binary

}

 

九、跨平台编译项目

针对不同平台使用不同配置

 

win32:INCLUDEPATH += “C:/mylibs/extra headers”

win32{

message(win32)

}

不是linux的平台

!linux{

message(win32)

}

 

如果是win32或linux

win32|linux{

message(win32)

}

 

QT内置定义了一些值 win32 linux macx unix

变量 QMAKESPEC 存储了当前的编译环境 message($$QMAKESPEC)可以打印出当前的编译环境。

我们可以查看

QT\5.13.0\msvc2017\mkspecs文件下的平台。

 

 最后附上一个pro文件

#指定源码
SOURCES += xsocket.cpp
#指定头文件
HEADERS += xsocket.h \
    xglobal.h
#指定生成的dll的名字
TARGET = libdll
#指定生成动态库
TEMPLATE = lib
#如果要生成静态库则需要再加一个
#CONFIG += staticlib
 
#添加LIBDLL_LIB宏
DEFINES +=LIBDLL_LIB
 
#指定dll的输出路径,只针对windows
DLLDESTDIR = ../../bin
 
#指定输出路径,编译生成的所有文件都会往这个路径输入
DESTDIR = ../../lib

Guess you like

Origin www.cnblogs.com/merlinzjl/p/11374811.html