我发现这个代码用于QT Creator并且是IDE的全新代码,但一直试图让这个代码运行。我看到的主要错误是与Qextserialport相关的12个类似错误的实例。
C:\ Users \用户Hassman \下载\ aQtLow \ aQtLow \ dtransferusb.cpp:
34:错误:未定义引用`QextSerialPort :: QextSerialPort(QextSerialPort :: QueryMode,QObject *)'
我不太清楚该怎么办,而且有点迷茫。我正在运行QTCreator 5.1.1,我想可能存在兼容性问题,但请有人帮我一把。也许我没有正确地将标题链接到我的文件?任何建议将不胜感激!
#include "dtransferusb.h"
#include <QDebug>
#include <QByteArray>
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport.h"
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport_p.h"
#include "globals.h"
dtransferusb::dtransferusb(QObject *parent) :
QThread(parent)
{
}
void dtransferusb::run()
{
SerPort= new QextSerialPort();
int ExpectedLength = NUMBER_OF_REGISTERS * 2 + NUMBER_OF_COILS / 8 + 1;
QTime Startup, Sleeper;
Startup.start();
while(!Shutdown)
{
if(SerPort->isOpen())
{//the port is open so check for data
Sleeper.start();
while((ExpectingResponse > 0) && (SerPort->bytesAvailable() < ExpectedLength))
{
msleep(25);
if(Sleeper.elapsed() > 5000) break;
}
if(SerPort->bytesAvailable() >= ExpectedLength)
{//data found
Receive(ExpectedLength);
}
else
{
if((ExpectingResponse > 2) && (Startup.elapsed() > 15000))
{
qDebug() << "DTxfrUsb " << QString::number(Cfg.DTxfrUsb) << " finds the lack of expected response utterly demoralizing " << SerPort->portName() << " " << QDateTime::currentDateTime().toString(TIMESTAMP_FORMAT);
P[Cfg.Prc].CommFailure();
ExpectingResponse = 0;
SerPort->close();
Sleeper.start();
while(Sleeper.elapsed() < 1000) msleep(100);
}
else
{
if(!WriteRequest())
{
Send(1,0,0); //Function 1 siginfies "gimme data"
}
}
}
}
else
{//need to open the port
SerPort->reset();
SerPort->setPortName(Cfg.Port);
SerPort->setBaudRate(BAUD9600);
SerPort->setDataBits(DATA_8);
SerPort->setStopBits(STOP_1);
SerPort->setFlowControl(FLOW_OFF);
SerPort->setParity(PAR_NONE);
SerPort->setTimeout(1000);
答案 0 :(得分:2)
QextSerialPort是第三方库,与官方Qt项目无关。您可以在https://code.google.com/p/qextserialport/找到它 - 您需要单独安装QextSerialPort。
一些额外的说明:
答案 1 :(得分:1)
(1)要在您的应用程序中使用这些类,请使用以下include语句:
#include <QtSerialPort/QtSerialPort>
(2)要链接模块,请将此行添加到qmake .pro文件中:
QT += serialport