Reputation: 252
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"
Upvotes: 1
Views: 919
Reputation: 6776
The error message is generated by linker. It means that it cannot find QextSerialPort
library binaries.
According to QextSerialPort Manual QextSerailPort
in Qt4 can be used only in Compat Mode:
Can be used as static or shared library, or simply integrate the component into application.
The simplest solution is just to build QextSerailPort
together with your main project. Just include it to your project file (.pro
):
include(pathToQesp/compat/qextserialport.pri)
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 test
git clone https://github.com/qextserialport/qextserialport
extserialtest
, so you have two folders:
qextserialport
with QextSerailPort
packageextserialtest
with your Qt projectinclude (../qextserialport/src/qextserialport.pri)
into extserialtest.pro
#include <qextserialport.h>
and new QextSerialPort("/dev/ttyACM0");
Verified on Qt 4.8.3 in Linux that it works out of the box.
Upvotes: 5