我见过几个问题,在googled上搜索了很多,我找不到一种方法来使用qextserialport来声明一个串行端口对象,以便读取和写入一个arduino。我尝试了用户在如何使用Qextserialport端口在串口上写入中所做的工作,但是编译器给出了以下错误:
undefined reference to `QextSerialPort::QextSerialPort(QString const&, QextSerialPort::QueryMode, QObject*)'下面是我使用的代码:
#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");
}为什么会出现此错误?我正在使用Debian 8.2和QT 4.8.6
编辑:添加行后的:
CONFIG += qesp_linux_udev
QT += extserialport对于项目文件,我有以下错误:
"Project MESSAGE: Warning: unknown QT: extserialport"发布于 2015-09-27 23:36:55
错误消息由链接器生成。这意味着它找不到QextSerialPort库二进制文件。
根据QextSerialPort手册,QextSerailPort in Qt4只能在Compat模式下使用
可以用作静态或共享库,也可以简单地将组件集成到应用程序中。
最简单的解决方案就是与您的主要项目一起构建QextSerailPort。只需将其包含到项目文件(.pro)中即可:
include(pathToQesp/compat/qextserialport.pri)您不需要QT += extserialport,因为在Compat中,它不被用作Qt模块。
最简单的HowTo
mkdir test && cd testgit clone https://github.com/qextserialport/qextserialportextserialtest,因此您有两个文件夹:qextserialport包的QextSerailPortextserialtest与您的Qt项目
include (../qextserialport/src/qextserialport.pri)添加到extserialtest.pro中#include <qextserialport.h>和new QextSerialPort("/dev/ttyACM0");在Linux的QT4.8.3上验证了它是开箱即用的。
https://stackoverflow.com/questions/32813681
复制相似问题