Question

i found this code for QT Creator and am brand new to the IDE, but have been trying to get this code to run. The main error I am seeing is about 12 instances of similar errors related to Qextserialport.

C:\Users\Hassman\Downloads\aQtLow\aQtLow\dtransferusb.cpp:

34: error: undefined reference to `QextSerialPort::QextSerialPort(QextSerialPort::QueryMode, QObject*)'

I'm not quite sure what to do about it, and am kind of lost. I am running QTCreator 5.1.1 and I imagine there may be a compatibility issue, but please someone give me a hand. Maybe I haven't linked the header to my file correctly? Any suggestions would be appreciated!

#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);
Was it helpful?

Solution

QextSerialPort is a 3rd-party library that is not affiliated with the official Qt Project. You can find it at https://code.google.com/p/qextserialport/ -- You will need to install QextSerialPort separately.

Some extra notes:

  • Since you are new, I recommend using Qt 5.2.1 instead. It has many new features and bug fixes over Qt 5.1.1.
  • "Qt Creator" is the name of the IDE, "Qt" is the name of the libraries. The current version of the IDE is Qt Creator 3.1, the current version of the libraries is Qt 5.2.1.
  • Qt has its own built-in QSerialPort class, which I recommend if you want to write your own code.

OTHER TIPS

(1) To use these classes in your application, use the following include statement:

 #include <QtSerialPort/QtSerialPort>

(2) To link against the module, add this line to your qmake .pro file:

 QT += serialport

Qt Serial Port Documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top