0

I'm facing a odd problem with QSerialPortInfo on Qt Creator. To illustrate the problem as simple as possible lets look at this small code snippet.

.pro

I have included CONFIG += serialport of course.

main.cpp

#include <QGuiApplication>
#include <QTimer>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);

    QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
    QList<QSerialPortInfo>::iterator i;
    for(i = ports.begin(); i != ports.end(); i++)
    {
    printf("Port:\n");
    printf(" - Name: %s\n", (*i).portName().toStdString().data());
    printf(" - Description: %s\n", (*i).description().toStdString().data());
    printf(" - Manufacturer: %s\n", (*i).manufacturer().toStdString().data());
    printf(" - Serial number: %s\n", (*i).serialNumber().toStdString().data());
    printf(" - System location: %s\n", (*i).systemLocation().toStdString().data());
    printf("\n");

    QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
    return a.exec();
}

This is a quite simple example of how to query the system for devices connected to it, however when I compile this on QtCreator, make reports all methods as undefined.

undefined reference to `QSerialPortInfo::availablePorts()'
undefined reference to `QSerialPortInfo::portName() const'
undefined reference to `QSerialPortInfo::description() const'
undefined reference to `QSerialPortInfo::manufacturer() const'
undefined reference to `QSerialPortInfo::serialNumber() const'
undefined reference to `QSerialPortInfo::systemLocation()'

Also tried #include <QtSerialPort/qserialportinfo.h> to be sure, yet no changes.

I also took a look and the QSerialPort files exist under the Qt source folder and I believe I've included all necessary references to it.

I'm puzzled and don't know what I'm missing.

Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96

1 Answers1

8

Try this:

QT += serialport

instead of this:

CONFIG += serialport

Link: http://doc.qt.io/qt-5/qserialportinfo.html

jesterjunk
  • 2,342
  • 22
  • 18
Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • Ops my bad. Totally missed `QT += serialport` even though I had the docs loaded in from of me the whole time, thank you for pointing it out. I was missing my coffee :-) – Fábio Antunes Oct 06 '14 at 19:02
  • @Chernobyl , I have the same error. I do that but these errors display:Project MESSAGE: Warning: unknown QT: serialport Project MESSAGE: Warning: unknown QT: serialport – H.Ghassami Feb 12 '17 at 11:09
  • @H.Ghassami please check this https://wiki.qt.io/QtSerialPort it can be anything: maybe you use Qt4, maybe you didn't build or install serial port module, maybe you need CONFIG += serialport as was written in the link above. Unfortunately, I can't help more here. – Jablonski Feb 12 '17 at 20:46