编译环境:
1、qextserialport 1.1
2、QT 4.3.2
3、VC++ 2003
1.在官网下载QextSerialPort最新版qextserialport-1.1.tar.gz,解压到qextserialport-1.1目录中。
2.将qextserialport-1.1目录下的qextserialport拷贝到Qt安装目录下的src目录中
3.进入src目录下的qextserialport目录,输入一下命令编译:
qmake
nmake
4.然后在qextserialport目录下的build目录下可得到qextserialport.dll,qextserialport.prl,libqextserialport.a三个文件,将qextserialport.dll复制到Qt安装目录下的bin目录中,将qextserialport.prl,libqextserialport.a复制到Qt安装目录下的lib目录中。(默认一般生成DLL和PRL,生成LIB参见附录步骤)
Linux下通过Config += static 生成静态库libqextserialport.a
5.在Qt安装目录下的include目录下的Qt目录中新建文件qextserialport.h,文件内容为:
#include "http://www.cnblogs.com/src/qextserialport/qextserialport.h"
并将该文件复制到Qt安装目录下的include目录下的QtGui目录中,并在该目录中再新建一个文件QextSerialPort(无扩展名),该文件内容为:
#include “qextserialport.h”
6.将src/qextserialport目录中的example目录拷贝到硬盘的其他地方,删除例子目录下的Makefile.Release, Makefile, Makefile.Debug,README和QESPTA.pro几个文件。
7.打开例子目录中的main.cpp和QespTest.cpp文件,修改#include <qextserialport.h>为#include <QextSerialPort>
8.编译自带EXAMPLE:进入EXAMPLE目录,输入:
Qmake –project
得到工程文件qespta.pro,打开该工程文件,如果当前系统为win32,加入语句:
LIBS
win32:DEFINES = _TTY_WIN_ QWT_DLL QT_DLL
如果当前系统为unix/linux,加入语句:
LIBS
unix:DEFINES
9.编译
qmake
nmake
如果编译成功证明已经扩展成功
10.该扩展帮助文档位于src/qextserialport目录中,可供查阅
注意,此扩展方法将类QextSerialPort扩展至QtGui下,请勿将类QextSerialPort误认为QtGui的一部分
附录:如何生成qextserialport.lib。
qmake默认是生成动态库版本,静态链接文件生成需要修改qextserialport.pro。(关于qmake参数说明可参见: http://www.cppblog.com/mydriverc/articles/32728.html )
1、打开qextserialport.pro
2、修改
CONFIG
为
CONFIG
注意:(http://www.itworld2.com/qtcompilation.aspx)
编译时可能会遇到如下错误:previous declaration 'long int InterlockedIncrement(long int*)' here
此为qt的bug需要修改源代码(Qt\4.4.3\src\corelib\arch\qatomic_windows.h),
原文件如下:
- #if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)
- extern "C" {
- __declspec(dllimport) long __stdcall InterlockedCompareExchan
ge(long *, long, long); - __declspec(dllimport) long __stdcall InterlockedIncrement(long *);
- __declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
- __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);
- }
- #else
- extern "C" {
- __declspec(dllimport) long __stdcall InterlockedCompareExchan
ge(long volatile*, long, long); - __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
- __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
- __declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
- __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
- }
- #endif
-
- 修改如下:
-
- extern "C" {
- __declspec(dllimport) long __stdcall InterlockedCompareExchan
ge(long volatile*, long, long); - __declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
- __declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
- __declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
- __declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
- }
- // #endif