总结一下一些用到的模板,后续会有补充。
1. 链接第三方库
①unix与Windows使用相对路径链接第三方库模板
代码语言:javascript复制unix{
contains(QT_ARCH, i386){
LIBS = -L$$PWD/Lib/Qsci/linux_x32/lib -lqscintilla2_qt5
INCLUDEPATH = $$PWD/Lib/Qsci/linux_x32/include
}
contains(QT_ARCH, x86_64){
}
}else{
contains(QT_ARCH, i386){
#32bit python
LIBS = -L$$PWD/lib/python/ -lpython37
INCLUDEPATH = $$PWD/lib/python/include
}
contains(QT_ARCH, x86_64){
#64bit
message(STATUS"********64********$$PWD/lib/python")
}
}
②Qt pro文件中定义变量并使用
代码语言:javascript复制DEFINES = PYTHON_VERSION_2
contains(DEFINES, PYTHON_VERSION_3) {
#32bit python3.5
message("***********PYTHON_VERSION_3**********")
}else{
message("***********PYTHON_VERSION_2**********")
}
③ unix 下 Qt 生成共享库设置名称及版本号
代码语言:javascript复制VERSION = 1.3.5
TARGET = mytest
TEMPLATE = lib
2. Linux 下Qt 一些文档路径
Linux 下Qt帮助文档路径
/opt/Qt5.5.1/5.5/gcc/bin 帮助文档路径
3. Qt 设置存储路径
代码语言:javascript复制#include <QDir>
QDir currentDir = QDir::current();
currentDir.cd("..");
currentDir.cd("ThreadClientSendPicture");
QString picturePath = currentDir.absolutePath();
// qDebug() << "~~~~~~~~~`" << currentDir.absolutePath();
4. Qt 读取图片转换为字节
代码语言:javascript复制 m_picturePath = m_picturePath "/auboi5.jpg"; //图片路径
QPixmap pix;
bool ret = pix.load(m_picturePath);
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
bool ret2 = pix.save(&buffer,"jpg");
QByteArray pictureByteArray = buffer.data();
if(ret2)
{
QString str = "read image finish!";
ui->textEdit->append(str);
}