I have seen several questions and googled a lot and I can't find a way to declare a serial port object using qextserialport, in order to read and write to/from an arduino. I tried what the user did in How to write on serial port using Qextserialport, but the compiler gives me the following error:
undefined reference to `QextSerialPort::QextSerialPort(QString const&, QextSerialPort::QueryMode, QObject*)'
Here is the code I'm using:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtExtSerialPort/qextserialport.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_BTN_Connect_clicked()
{
int index=ui->Selector_Port->currentIndex();
QextSerialPort *port = new QextSerialPort("/dev/ttyACM0");
}
Why does this error appear? I'm using Debian 8.2 and QT 4.8.6
EDIT: After adding the lines:
CONFIG += qesp_linux_udev
QT += extserialport
to the project file, I'm having the following error:
"Project MESSAGE: Warning: unknown QT: extserialport"
The error message is generated by linker. It means that it cannot find
QextSerialPortlibrary binaries.According to QextSerialPort Manual
QextSerailPortin Qt4 can be used only in Compat Mode:The simplest solution is just to build
QextSerailPorttogether with your main project. Just include it to your project file (.pro):You do not need
QT += extserialport, since in the Compat Mode it is not used as a Qt module.The simplest HowTo
mkdir test && cd testgit clone https://github.com/qextserialport/qextserialportextserialtest, so you have two folders:qextserialportwithQextSerailPortpackageextserialtestwith your Qt projectinclude (../qextserialport/src/qextserialport.pri)intoextserialtest.pro#include <qextserialport.h>andnew QextSerialPort("/dev/ttyACM0");Verified on Qt 4.8.3 in Linux that it works out of the box.