QtCreator的中如何使用第三方依赖库

      之前项目里使用其它的第三方库都是leader或同事给配置好的,从没操心这回事,真是惭愧,哭。今天同学给我发来一个工程,需用使用到Qt库和Qwt库,用QtCreator打开编译,提示找不到Qwt库里的头文件,于是试着配置一下,居然折腾了许久还没运行起来。后来看了一下Qt的qmake文档,才得以搞定。qmake 的说明文档里有关于声明使用其它库的说明:

Declaring Other Libraries

If you are using other libraries in your project in addition to those supplied with Qt, you need to specify them in your project file.

The paths that qmake searches for libraries and the specific libraries to link against can be added to the list of values in the LIBS variable. The paths to the libraries themselves can be given, or the familiar Unix-style notation for specifying libraries and paths can be used if preferred.

For example, the following lines show how a library can be specified:

 LIBS += -L/usr/local/lib -lmath

The paths containing header files can also be specified in a similar way using the INCLUDEPATH variable.

For example, it is possible to add several paths to be searched for header files:

 INCLUDEPATH = c:/msdev/include d:/stl/include

    如果电脑上已经安装了Qt 和Qwt的环境,那么对于一个需要使用Qwt的程序来说,只需要在其工程文件中添加如下配置:

(假设你的Qwt安装目录为 C:/Qwt-6.0.1 )

1)在 LIBS 变量后面添加链接这个库的路径(例如-LC:/Qwt-6.0.1/lib)和名称(例如 -lqwt, 也可以用 qtAddLibrary(qwt) 添加动态库

2)在INCLUDEPATH variable.后面添加这个引用该库所需要的头文件(例如 C:/Qwt-6.0.1/include

 

#include( $${PWD}/../examples.pri )
#include( ../3rdparty/qwt/qwtplot.pri )
#include( C:/Qwt-6.0.1/features/qwtconfig.pri )
INCLUDEPATH += C:/Qwt-6.0.1/include #必须有
#DEPENDPATH  += C:/Qwt-6.0.1/lib
#LIBS += -L/usr/local/lib -lmath
LIBS      += -LC:/Qwt-6.0.1/lib -lqwt #必须有 否则报错 :-1: error: cannot find -lqwt
#qtAddLibrary(qwt) #必须有

#CONFIG += qwt




 

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
QT Creator使用qpainter绘制Codabar码,可以按照以下步骤进行: 1. 在QT Creator创建一个新的QWidget项目。 2. 在QWidget重写paintEvent()函数,使用QPainter对象进行绘制。 3. 在paintEvent()函数使用QPainter的绘制函数绘制条码。 4. Codabar条码的编码规则如下: - 有效字符范围:数字0-9、字符(-、$、:、/、.、+)。 - 起始符和终止符:A、B、C、D。 - 字符编码:每个字符由7个模块组成,由条和空组成,共有20种不同的编码方式。 - 校验码:根据权重系数计算校验和,校验和是最后一位字符。 5. 根据编码规则,可以使用QPainter的drawRect()函数绘制条码,根据字符编码,使用条和空分别绘制每个字符。 下面是一个简单的Codabar条码绘制示例代码: ```c++ void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(Qt::black); painter.setBrush(Qt::black); painter.drawRect(QRect(0, 0, width(), height())); QString code = "A1234B"; int width = this->width(); int height = this->height(); int x = 0; int y = 0; int barWidth = 2; int barHeight = height - 4; int charWidth = 7 * barWidth; QPen pen(Qt::white, 1, Qt::SolidLine); // 绘制起始符 drawBar(painter, x, y, barWidth, barHeight, true); x += barWidth; // 绘制字符 for (int i = 0; i < code.length(); i++) { int c = code[i].toLatin1(); int charCode = getCharCode(c); for (int j = 0; j < 7; j++) { bool b = ((charCode >> (6 - j)) & 0x01) != 0; drawBar(painter, x, y, barWidth, barHeight, b); x += barWidth; } // 绘制字符之间的空白 if (i < code.length() - 1) { drawBar(painter, x, y, barWidth, barHeight, false); x += barWidth; } } // 绘制校验码 int checkCode = getCheckCode(code); for (int j = 0; j < 7; j++) { bool b = ((checkCode >> (6 - j)) & 0x01) != 0; drawBar(painter, x, y, barWidth, barHeight, b); x += barWidth; } // 绘制终止符 drawBar(painter, x, y, barWidth, barHeight, true); x += barWidth; } void Widget::drawBar(QPainter &painter, int x, int y, int width, int height, bool black) { QPen pen = painter.pen(); if (black) { pen.setColor(Qt::black); painter.setPen(pen); painter.setBrush(Qt::black); } else { pen.setColor(Qt::white); painter.setPen(pen); painter.setBrush(Qt::white); } painter.drawRect(QRect(x, y, width, height)); } int Widget::getCharCode(int c) { int charCode = 0; switch (c) { case '-': charCode = 0x0D; break; case '$': charCode = 0x0E; break; case ':': charCode = 0x0F; break; case '/': charCode = 0x10; break; case '.': charCode = 0x11; break; case '+': charCode = 0x12; break; default: if (c >= '0' && c <= '9') { charCode = c - '0' + 0x03; } break; } return charCode; } int Widget::getCheckCode(QString code) { int checkCode = 0; int weight[] = {1,1,2,2,3,3,4,4}; for (int i = 0; i < code.length() - 1; i++) { int c = code[i].toLatin1(); int charCode = getCharCode(c); checkCode += weight[i % 8] * charCode; } checkCode %= 16; checkCode = (16 - checkCode) % 16; return checkCode; } ``` 这个示例代码可以绘制Codabar条码,并且不依赖任何第三方库

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值