从网上下了一个第三方的串口类.自己写了一个主函数,如下:
#include <qapplication.h>
#include <qlabel.h>
#include "posix_qextserialport.h"
int main(int argc , char **argv)
{
QApplication myApp(argc,argv);
QLabel myLabel("Hello",0);
Posix_QextSerialPort * RS232 = new Posix_QextSerialPort("/dev/ttyS0");
RS232->setBaudRate(BAUD115200); //com1,115200,n,8,1
RS232->setFlowControl(FLOW_OFF);
RS232->setParity(PAR_NONE);
RS232->setDataBits(DATA_8 );
RS232->setStopBits(STOP_1);
if (RS232->open())
{
RS232->putch('a');
RS232->putch('a');
RS232->flush();
RS232->close();
}
myApp.setMainWidget(&myLabel);
myLabel.show();
return myApp.exec();
}
将qextserialbase.h qextserialbase.cpp及posix_qextserialport.h posix_qextserialport.cpp放在程序路径下,
progen -o main.pro
tmake main.pro -o Makefile
make,出错,错误如下:
qextserialbase.h:174: ISO C++ forbids declaration of `Offset' with no type
qextserialbase.h:174: `Offset' declared as a `virtual' field
qextserialbase.h:174: parse error before `(' token
qextserialbase.h:204: ISO C++ forbids declaration of `Q_LONG' with no type
qextserialbase.h:204: `Q_LONG' declared as a `virtual' field
qextserialbase.h:204: parse error before `(' token
qextserialbase.h:205: ISO C++ forbids declaration of `Q_LONG' with no type
qextserialbase.h:205: `Q_LONG' declared as a `virtual' field
qextserialbase.h:205: declaration of `int QextSerialBase::Q_LONG'
qextserialbase.h:204: conflicts with previous declaration `int
QextSerialBase::Q_LONG'
qextserialbase.h:205: parse error before `(' token
qextserialbase.h:205: duplicate member `QextSerialBase::Q_LONG'
In file included from main.cpp:3:
posix_qextserialport.h:29: syntax error before `;' token
posix_qextserialport.h:44: ISO C++ forbids declaration of `Offset' with no type
posix_qextserialport.h:44: `Offset' declared as a `virtual' field
posix_qextserialport.h:44: parse error before `(' token
posix_qextserialport.h:64: ISO C++ forbids declaration of `Q_LONG' with no type
posix_qextserialport.h:64: `Q_LONG' declared as a `virtual' field
posix_qextserialport.h:64: parse error before `(' token
posix_qextserialport.h:65: ISO C++ forbids declaration of `Q_LONG' with no type
posix_qextserialport.h:65: `Q_LONG' declared as a `virtual' field
posix_qextserialport.h:65: declaration of `int Posix_QextSerialPort::Q_LONG'
posix_qextserialport.h:64: conflicts with previous declaration `int
Posix_QextSerialPort::Q_LONG'
posix_qextserialport.h:65: parse error before `(' token
posix_qextserialport.h:65: duplicate member `Posix_QextSerialPort::Q_LONG'
main.cpp: In function `int main(int, char**)':
main.cpp:9: cannot allocate an object of type `Posix_QextSerialPort'
main.cpp:9: because the following virtual functions are abstract:
/opt/qt_x86/qt/include/qiodevice.h:119: virtual uint QIODevice::size() const
/opt/qt_x86/qt/include/qiodevice.h:125: virtual int
QIODevice::readBlock(char*, unsigned int)
/opt/qt_x86/qt/include/qiodevice.h:126: virtual int
QIODevice::writeBlock(const char*, unsigned int)
make: *** [main.o] Error 1
貌似是条件编译的错误,但是不知道该怎么改,还请大家指点迷津.