- 运行效果
![QT串口调试时间显示图片](https://img-blog.csdnimg.cn/2020052821273253.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2p1bmhlbmcwODEy,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200528212832839.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2p1bmhlbmcwODEy,size_16,color_FFFFFF,t_70)
- widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QDebug>
#include <QTextCodec>
#include <QMessageBox>
#include <QImage>
#include <QPixmap>
#include <QTimer>
#include <QDateTime>
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_OpenCom_clicked();
void timeUpdate();
private:
Ui::Widget *ui;
QSerialPort *serial;
QTimer *timer;
};
#endif
- widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
foreach (const QSerialPortInfo &info