Qt串行通信
Qt serial communication
我刚刚尝试了以下代码。但是老虎机功能不起作用。连接正常,我通过 qDubug 发现了它。控制台输出如下所示。
[ZDSGuard] 32 DllMain hook strProductName2 : C:qt_examplebuild-
serial_test-Desktop_Qt_5_13_1_MinGW_32_bit-Debugdebugserial_test.exe-1
ddd
ss
ccc
如您所见,aaa
没有打印出来。如果插槽功能工作正常,则应打印。
如果有人发现问题所在,请告诉我。 提前谢谢。
[ZDSGuard] 32 DllMain hook strProductName2 : C:qt_examplebuild-
serial_test-Desktop_Qt_5_13_1_MinGW_32_bit-Debugdebugserial_test.exe-1
ddd
ss
ccc
串行通信代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QDebug>
#include <QLabel>
QSerialPort *serial;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
serial = new QSerialPort();
serial->setPortName("COM4");
serial->setBaudRate(QSerialPort::Baud115200);
serial->setFlowControl(QSerialPort::NoFlowControl);
serial->setParity(QSerialPort::NoParity);
serial->setDataBits(QSerialPort::Data8);
serial->setStopBits(QSerialPort::OneStop);
if (serial->open(QIODevice::ReadWrite))
ui->label->setText("bb");
if (QObject::connect(serial,SIGNAL(readyRead()),this,SLOT(serialReceived())))
qDebug()<< "ddd";
//ui->label->setText("aa");
qDebug() << "ss";
}
MainWindow::~MainWindow()
{
delete ui;
serial->close();
}
void MainWindow::serialReceived()
{
QByteArray BA;
BA=serial->readAll();
ui->label->setText("aa");
//printf(BA);
qDebug()<<"aaa";//BA;
}
QSP 在 Qt 5.13.1 中有错误。使用或Qt 5.13.0,或等待最新版本(5.13.2/5.12.6(。
相关文章:
- 通过插槽和信号在不同线程中的两个qt对象之间进行通信
- 如何使用带有Qt和C++的"Interface Class"进行通信
- Qt串行通信
- 与处理 ZeroMQ 的永久线程与 Qt 通信
- 如何在Qt WebChannel中以独立于平台的方式在HTML/Javascript和C++之间进行通信?
- QT 中的串行通信超时与 Arduino
- 覆盆子Pi(QT C )和Arduino(Arduino IDE)之间的通信
- 通过Modbus TCP与CMMO-ST-C5-1-LKP Festo控制器进行Qt/C++通信
- Qt中的多线程通信
- Qt中数据类(模型)和视图/控制器类之间的数据通信的正确方式是什么
- 如何与qt c 之间在qdialog窗口和qmainwindow之间进行通信
- 在QT中的两个窗口之间进行通信的最佳方法是什么?
- Qt.中线程间通信的实现
- VC++和Qt应用程序之间使用共享内存进行通信
- Qt多线程通信
- 如何通过外部命令与Qt小部件进行通信
- Qt,tcp/ip通信校验和
- Qt 5.1 使用 QSerialPort 的串行通信
- 通过 erlang 端口在 qt 应用程序和 erlang 服务器之间进行通信
- Qt TCP/IP通信只能在本地工作,但在网络中会丢失