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

制作公司网站视频商务软文写作范文200字

制作公司网站视频,商务软文写作范文200字,松原做网站,国外h5网站模板练习1:Qt 进度条与多线程应用 题目描述 开发一个基于 Qt 的应用程序,该应用程序包含一个水平进度条(QSlider),并且需要通过多线程来更新进度条的值。请根据以下要求完成代码: 界面设计: 使用 QS…

练习1:Qt 进度条与多线程应用

题目描述

开发一个基于 Qt 的应用程序,该应用程序包含一个水平进度条(QSlider),并且需要通过多线程来更新进度条的值。请根据以下要求完成代码:

  1. 界面设计

    • 使用 QSlider 控件作为进度条。

    • 设置 QSlider 的样式

  2. 多线程更新

    • 创建一个自定义线程类 mythread,该线程类继承自 QThread

    • 使主线程接收到信号后,更新 QSlider 的值。

  3. 信号与槽

    • 使用信号与槽机制实现线程与主线程之间的通信。

    • 当线程中的值发生变化时,通过信号通知主线程更新进度条。

1.mythread.h 

#ifndef MYTHREAD_H
#define MYTHREAD_H
#include<QThread>class mythread : public QThread
{Q_OBJECT
public:explicit mythread(QObject *parent = nullptr);void run() override; // 线程的执行函数signals:void updateValue(int value); // 发送信号更新进度条
};#endif // MYTHREAD_H

2.mythread.cpp 

#include "mythread.h"
#include<QThread>mythread::mythread(QObject *parent){}
void mythread::run()
{int value = 0;while (true) {emit updateValue(value);value = (value + 1) % 101;  // 0 ~ 100 循环QThread::msleep(100);  // 休眠 100ms}
}

3.widget.h 

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QWidget>
#include <QMovie>
#include <QThread>
#include <QTextEdit>
#include <QWidget>
#include <QThread>
#include<QScreen>
#include<QLabel>
#include<QDebug>
#include<QPixmap>
#include<QApplication>
#include<QPushButton>
#include "mythread.h"QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECT
public slots:void setSliderValue(int value); // 更新进度条public:Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;mythread *thread;
};
#endif // WIDGET_H

4.widget.cpp 

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);QString qss = "QSlider { background: transparent; }"//设置 QSlider 的背景为透明"QSlider::groove:horizontal { border: 1px solid gray; background: lightgray; height: 15px; border-radius: 5px; }""QSlider::sub-page:horizontal { background: #B5E61D; border-radius: 5px; }""QSlider::handle:horizontal { background:#5A730E; width: 10px;border-radius: 5px }";ui->horizontalSlider->setStyleSheet(qss);// 创建并启动线程thread = new mythread(this);connect(thread, &mythread::updateValue, this, &Widget::setSliderValue);thread->start();}Widget::~Widget()
{delete ui;
}// 槽函数:更新进度条
void Widget::setSliderValue(int value)
{ui->horizontalSlider->setValue(value);
}

练习2:基于 Qt 的文件复制工具开发

开发一个基于 Qt 的文件复制工具,要求实现以下功能:

  1. 文件选择

    • 使用 QFileDialog 选择源文件和目标文件。

    • 支持选择大文件(超过 800MB)。

  2. 文件复制

    • 使用 Qt 的文件 IO 操作(QFile)实现文件复制功能。

    • 支持分块读取和写入文件,避免一次性加载大文件到内存中。

  3. 多线程处理

    • 使用 QThread 在后台执行文件复制操作,避免阻塞主线程。

    • 通过信号与槽机制,将复制进度实时传递给主线程。

  4. 进度显示

    • 使用自定义的 QSlider 作为进度条,显示文件复制的进度。

    • 自定义 QSlider 的样式,使其外观美观。

  5. 错误处理

    • 如果文件打开失败或复制失败,弹出错误提示框。

    • 如果复制完成,弹出提示框显示“文件复制完成”。

1.mythread.h

#ifndef MYTHREAD_H
#define MYTHREAD_H#include <QThread>
#include <QString>class MyThread : public QThread
{Q_OBJECTpublic:explicit MyThread(const QString &source, const QString &destination, QObject *parent = nullptr);signals:void progressUpdated(int value); // 信号:用于更新进度条的值protected:void run() override; // 线程执行函数private:QString sourcePath;  // 源文件路径QString destinationPath; // 目标文件路径
};#endif // MYTHREAD_H

2.mythread.cpp 

#include "mythread.h"
#include <QFile>
#include <QDebug>MyThread::MyThread(const QString &source, const QString &destination, QObject *parent): QThread(parent), sourcePath(source), destinationPath(destination)
{
}void MyThread::run()
{QFile sourceFile(sourcePath);QFile destinationFile(destinationPath);// 打开源文件if (!sourceFile.open(QIODevice::ReadOnly)) {emit progressUpdated(-1); // 发送错误信号return;}// 打开目标文件if (!destinationFile.open(QIODevice::WriteOnly)) {emit progressUpdated(-1); // 发送错误信号return;}qint64 fileSize = sourceFile.size(); // 获取文件大小qint64 bytesCopied = 0; // 已复制的字节数char buffer[4096]; // 缓冲区// 分块读取和写入文件while (!sourceFile.atEnd()) {qint64 bytesRead = sourceFile.read(buffer, sizeof(buffer)); // 读取数据destinationFile.write(buffer, bytesRead); // 写入数据bytesCopied += bytesRead; // 更新已复制的字节数int progress = static_cast<int>((bytesCopied * 100) / fileSize); // 计算进度emit progressUpdated(progress); // 发送进度信号}// 关闭文件sourceFile.close();destinationFile.close();
}

3.widget.h 

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QSlider>
#include <QFileDialog>
#include <QMessageBox>
#include "mythread.h"QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void updateProgress(int value); // 槽函数:更新进度条private:Ui::Widget *ui;MyThread *thread; // 文件复制线程
};#endif // WIDGET_H

 4.widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QMessageBox>Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);// 设置 QSlider 的样式QString qss = "QSlider { background: transparent; }" // 设置 QSlider 的背景为透明"QSlider::groove:horizontal { border: 1px solid gray; background: lightgray; height: 15px; border-radius: 5px; }""QSlider::sub-page:horizontal { background: #B5E61D; border-radius: 5px; }""QSlider::handle:horizontal { background:#5A730E; width: 10px; border-radius: 5px; }";ui->horizontalSlider->setStyleSheet(qss);ui->horizontalSlider->setRange(0, 100); // 设置进度条范围ui->horizontalSlider->setValue(0); // 初始值为 0// 选择源文件QString sourceFile = QFileDialog::getOpenFileName(this, "选择要复制的文件");if (sourceFile.isEmpty()) {QMessageBox::warning(this, "警告", "未选择源文件");return;}// 选择目标文件QString destinationFile = QFileDialog::getSaveFileName(this, "选择保存位置");if (destinationFile.isEmpty()) {QMessageBox::warning(this, "警告", "未选择目标文件");return;}// 创建并启动线程thread = new MyThread(sourceFile, destinationFile, this);connect(thread, &MyThread::progressUpdated, this, &Widget::updateProgress);thread->start();
}Widget::~Widget()
{if (thread) {thread->quit(); // 停止线程thread->wait(); // 等待线程结束delete thread; // 释放线程对象}delete ui;
}// 槽函数:更新进度条
void Widget::updateProgress(int value)
{if (value == -1) {QMessageBox::critical(this, "错误", "文件复制失败");return;}ui->horizontalSlider->setValue(value); // 更新 QSlider 的值if (value == 100) {QMessageBox::information(this, "完成", "文件复制完成");}
}

http://www.dtcms.com/wzjs/29328.html

相关文章:

  • 云南网站建设快速排名百度站长平台提交网站
  • .net怎么做网站seo搜索引擎优化介绍
  • 邯郸市恒诚网络科技有限公司seo诊断网站
  • 国家住房和城乡建设部中国建造师网站官网武汉seo外包平台
  • 建筑方面的网站网站建设总结
  • 做音乐网站要什么源码旅游推广赚佣金哪个平台好
  • 广州市做网站的网站如何宣传推广
  • 网站维护与建设ppt网站快速排名优化价格
  • 2345网址导航主页郑州专业seo推荐
  • 网站的用户体验网站优化方案范文
  • 网站制作公司crm客户管理系统十大计算机培训机构排名
  • 洞口做网站的公司浏览器老是出现站长工具
  • 什么网站可以做护考题整合营销传播名词解释
  • 做网站 徐州百度营稍
  • 企业网站的设计与开发关键词规划师工具
  • 在西部数码上再备案一个网站ftp小程序开发模板
  • 在什么网站可以自承包活来做前端seo是什么意思
  • 阜宁网站制作公司报价2345浏览器下载安装
  • 中国公司网站建设方案电商网络销售是做什么
  • 品牌如何推广关键词优化外包
  • 摄影网站设计说明书网站seo运营培训机构
  • 个人博客网站模板素材佛山优化推广
  • 不需要丢链接可以百度收录的网站怎么从网上找客户
  • 独立建站系统百度怎么推广自己的信息
  • 建设网站的技术难点百度收录最新方法
  • 网站建设能带来流量么凡科建站
  • 汽车网站首页模板代码电商平台开发
  • 正规网站优化公司如何优化推广中的关键词
  • 公司网站建设佛山哪家好官网设计公司
  • 手机wap网页海口seo计费