Linux系统编译QT5.15.0及串口问题
编译流程:
1> 下载QT源码
源码的下载可以到qt的官网
http://www.qt.io/download/
2> 解压
tar xvf qt-everywhere-src-x.x.x.tar.gz
注意后缀和解压方式
3> 配置
./configure 进行环境配制。
4> 编译
执行make编译,时间长,大概在三四个小时左右。
5> 安装
sudo make install
需要5分钟左右
6> 设置环境变量
sudo gedit /etc/profile
QTDIR=/usr/local/Qt-x.x.x{qt实际安装路径}
PATH=PATH
MANPATH=MANPATH
LD_LIBRARY_PATH=LD_LIBRARY_PATH
export QTDIR PATH MANPATHLD_LIBRARY_PATH
然后保存
source /etc/profile 使刚才的环境变量生效。
可以进行测试,
qmake -v
如果环境变量生效会出现:
QMake version 2.01a
Using Qt version 4.8.2 in /usr/local/Trolltech/Qt-xxx/lib
which qmake
会出现:
/usr/local/Trolltech/Qt-4.8.2/bin/qmake
只有设置了环境变量,后面的设置在qtcreator里面的编译器才会生效。
写在配置文件里面的,才能每次使用。
QtCreator 进行编译器设置
在qtcreator里面 Tools->Options->Qt->qmake location:
/usr/local/Trolltech/Qt-x.x.x/bin/qmake //系统默认是安装在这里的
进行编译器qmake设置和默认QT版本选择,然后就可以运行一个小实例了。
错误解决:
1. Project ERROR: xcb-xfixes development package not found
make[2]: *** [Makefile:52: sub-virtualkeyboard-make_first] Error 3
sudo apt-get install libxcb-xfixes0-dev libxcb-util-dev
2. ERROR: The OpenGL functionality tests failed!
You might need to modify the include and library search paths by editing QMAKE_INCDIR_OPENGL[_ES2],
QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your platform.
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
3. ERROR: Feature ‘xcb’ was enabled, but the pre-condition ‘features.thread && features.xkbcommon && libs.xcb’ failed
sudo apt-get install libxkbcommon-x11-dev
4. ERROR: Feature ‘fontconfig’ was enabled, but the pre-condition ‘!config.msvc && features.system-freetype && libs.fontconfig’ failed
sudo apt-get install libfontconfig1-dev
5. Project ERROR: Building QtQml requires Python
sudo apt-get install python3
sudo ln -s /usr/bin/python3 /usr/bin/python
6. Project ERROR: Unknown module(s) in QT_PRIVATE:serialport
sudo apt-get install libqt5serialport5 libqt5serialport5-dev
7. 打开串口失败(root权限)
可以 帮助-》关于插件 取消勾选ClangCodeModel
8. 串口发送大量数据出现丢失(windows平台正常,Linux平台出问题)
serial->waitForBytesWritten(-1)未按预期执行(失效?)
导致部分数据被serial->clear(QSerialPort::Output )清除。
发送代码:
void serial_object::UpgWrite(uint8_t * buf, uint32_t maxlen) { QByteArray tbuf; tbuf.resize((int)maxlen); memcpy(tbuf.data(), buf, maxlen); qDebug()<<maxlen; serial->write(tbuf, maxlen); serial->waitForBytesWritten(-1); serial->clear(QSerialPort::Output ); // Linux bug }
修改后正常:
void serial_object::UpgWrite(uint8_t * buf, uint32_t maxlen) { QByteArray tbuf; tbuf.resize((int)maxlen); memcpy(tbuf.data(), buf, maxlen); qDebug()<<maxlen; serial->write(tbuf, maxlen); serial->waitForBytesWritten(-1); //serial->clear(QSerialPort::Output ); // Linux bug }