"No matching function for call" 编译代码时。 [QTSerialPort开启读取]
"No matching function for call" when compile code. [QTSerialPort opening to read]
这里是自学菜鸟码农,有错请见谅。我正在尝试制作一个程序 send/read 串行数据,但它的读取部分有问题。我可以通过下拉 select 通信端口,并传输我需要的内容。当我开始使用大量在线示例对接收端进行编码时,它无法编译,我似乎无法弄清楚原因。如果我完全复制 QT 示例中的代码,它 可能 工作,但它不会做我想要的(即使用组合框下拉选项卡 selection )
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QApplication>
#include <QWidget>
#include <QSerialPort>
#include <QSerialPortInfo>
QString commPort;
QSerialPort serial;
QByteArray charBuffer;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) //populates the combo box with all availble comm ports.
{
ui->comboBox->addItem(serialPortInfo.portName());
commPort=serialPortInfo.portName();
}
}
MainWindow::~MainWindow()
{
delete ui;
serial.close();
}
void MainWindow::on_comboBox_activated(const QString &commPort) //selects the chosen comm port.
{
ui->report->setText(commPort);
}
void MainWindow::openSerialPort()
{
serial.setPortName(commPort);
if(serial.open(QIODevice::ReadWrite))
{
qDebug("Serial Opened");
ui->report->setStyleSheet("QLabel{background-color:'green';}");
serial.setBaudRate(QSerialPort::Baud9600);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);
//^^That is the part that fails to compile
}
else
{
ui->report->setStyleSheet("QLabel{background-color:'red';}");
qDebug ("Serial NOT Opened");
qDebug() << serial.error();
qDebug() << serial.errorString();
}
}
void MainWindow::on_connectButton_pressed()
{
openSerialPort();
}
void MainWindow::readSerial()
{
qDebug()<<("serial works");
}
*more code follows, but not needed....
表示 "connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);" 的行
是罪魁祸首给我的错误:
mainwindow.cpp:52: 错误:没有匹配函数来调用 'MainWindow::connect(QSerialPort&, void (QIODevice::)(), MainWindow const, void (MainWindow::*)())'
连接(串行,&QSerialPort::readyRead,这,&MainWindow::readSerial);
我试图阅读 QObject 和 QSerialPort 库的帮助信息,但是 SIGNAL 和 SLOT 的内容对于这个业余爱好者来说太混乱了。我还从网上获取了部分示例并粘贴以尝试修复它,...没有骰子。
您必须传递发件人的指针。
connect(const QObject *sender, const char *signal, const QObject
*receiver, const char *method, Qt::ConnectionType type)
connect(const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type)
connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
变化:
connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);
到
connect(&serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);
这里是自学菜鸟码农,有错请见谅。我正在尝试制作一个程序 send/read 串行数据,但它的读取部分有问题。我可以通过下拉 select 通信端口,并传输我需要的内容。当我开始使用大量在线示例对接收端进行编码时,它无法编译,我似乎无法弄清楚原因。如果我完全复制 QT 示例中的代码,它 可能 工作,但它不会做我想要的(即使用组合框下拉选项卡 selection )
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QApplication>
#include <QWidget>
#include <QSerialPort>
#include <QSerialPortInfo>
QString commPort;
QSerialPort serial;
QByteArray charBuffer;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) //populates the combo box with all availble comm ports.
{
ui->comboBox->addItem(serialPortInfo.portName());
commPort=serialPortInfo.portName();
}
}
MainWindow::~MainWindow()
{
delete ui;
serial.close();
}
void MainWindow::on_comboBox_activated(const QString &commPort) //selects the chosen comm port.
{
ui->report->setText(commPort);
}
void MainWindow::openSerialPort()
{
serial.setPortName(commPort);
if(serial.open(QIODevice::ReadWrite))
{
qDebug("Serial Opened");
ui->report->setStyleSheet("QLabel{background-color:'green';}");
serial.setBaudRate(QSerialPort::Baud9600);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::NoFlowControl);
connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);
//^^That is the part that fails to compile
}
else
{
ui->report->setStyleSheet("QLabel{background-color:'red';}");
qDebug ("Serial NOT Opened");
qDebug() << serial.error();
qDebug() << serial.errorString();
}
}
void MainWindow::on_connectButton_pressed()
{
openSerialPort();
}
void MainWindow::readSerial()
{
qDebug()<<("serial works");
}
*more code follows, but not needed....
表示 "connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);" 的行 是罪魁祸首给我的错误: mainwindow.cpp:52: 错误:没有匹配函数来调用 'MainWindow::connect(QSerialPort&, void (QIODevice::)(), MainWindow const, void (MainWindow::*)())' 连接(串行,&QSerialPort::readyRead,这,&MainWindow::readSerial);
我试图阅读 QObject 和 QSerialPort 库的帮助信息,但是 SIGNAL 和 SLOT 的内容对于这个业余爱好者来说太混乱了。我还从网上获取了部分示例并粘贴以尝试修复它,...没有骰子。
您必须传递发件人的指针。
connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
connect(const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type)
connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
connect(const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
变化:
connect(serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);
到
connect(&serial, &QSerialPort::readyRead, this,&MainWindow::readSerial);