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

定制直播appseo千享科技

定制直播app,seo千享科技,可视化编辑 wordpress,长沙微营销说明:复现的代码来自《Qt C6.0》P496-P500。在复现时完全按照代码,出现了两处报错: (1)ui指针(2)按钮的响应函数。下面程序对以上问题进行了修改。除了图片、清空、关闭功能外,其他…

说明:复现的代码来自《Qt C++6.0》P496-P500。在复现时完全按照代码,出现了两处报错:

(1)ui指针(2)按钮的响应函数。下面程序对以上问题进行了修改。除了图片、清空、关闭功能外,其他功能实现复现。


主线程:

.h文件

#pragma once#include <QtWidgets/QMainWindow>
#include "ui_ThreadTest_one.h"
#include "QtClass.h"class ThreadTest_one : public QMainWindow//主线程
{Q_OBJECTprivate:QtClass* threadA;protected:void closeEvent(QCloseEvent* event);public:ThreadTest_one(QWidget* parent = nullptr);~ThreadTest_one();private:Ui::ThreadTest_oneClass ui;public slots:void do_threadA_started();void do_threadA_finished();void do_threadA_newValue(int seq, int diceValue);void on_actThread_Run_clicked();void on_actDice_Run_clicked();void on_actThread_Quit_clicked();void on_actDict_Pause_clicked();
};

.cpp文件

#include "ThreadTest_one.h"
#include <QCloseEvent>
#include <QThread>ThreadTest_one::ThreadTest_one(QWidget *parent): QMainWindow(parent)
{ui.setupUi(this);threadA = new QtClass(this);//创建工作线程connect(threadA, &QtClass::started, this, &ThreadTest_one::do_threadA_started);connect(threadA, &QtClass::finished, this, &ThreadTest_one::do_threadA_finished);connect(threadA, &QtClass::newValue, this, &ThreadTest_one::do_threadA_newValue);
}void ThreadTest_one::do_threadA_started() {ui.statusBar->showMessage("Thread状态:thread start");ui.actThread_Run->setEnabled(false);ui.actThread_Quit->setEnabled(true);ui.actDice_Run->setEnabled(true);}
void ThreadTest_one::do_threadA_finished() {ui.statusBar->showMessage("Thread状态:thread finished");ui.actThread_Run->setEnabled(true);ui.actThread_Quit->setEnabled(false);ui.actDice_Run->setEnabled(false);ui.actDict_Pause->setEnabled(false);
}void ThreadTest_one::do_threadA_newValue(int seq, int diceValue) {//与线程的newValue()信号相关联QString str = QString::asprintf("第%d次投骰子,点数为%d", seq, diceValue);ui.plainTextEdit->appendPlainText(str);}//按键的槽函数
void ThreadTest_one::on_actThread_Run_clicked() {//要用clicked才能得到响应threadA->start();
}
void ThreadTest_one::on_actThread_Quit_clicked() {threadA->stopThread();
}
void ThreadTest_one::on_actDice_Run_clicked() {threadA->diceBegin();ui.actDice_Run->setEnabled(false);ui.actDict_Pause->setEnabled(true);
}
void ThreadTest_one::on_actDict_Pause_clicked() {threadA->dicePause();ui.actThread_Run->setEnabled(true);ui.actDict_Pause->setEnabled(false);
}//重定义事件处理函数,确保窗口关闭时线程被停止
void ThreadTest_one::closeEvent(QCloseEvent* event) {if (threadA->isRunning()) {threadA->terminate();threadA->wait();}event->accept();
}ThreadTest_one::~ThreadTest_one()
{}

工作线程:

.h文件

#pragma once#include <QThread>class QtClass  : public QThread
{Q_OBJECTpublic:QtClass(QObject *parent);~QtClass();
private:int m_seq = 0;   //掷骰子次数的序号int m_diceValue;//骰子的点数bool m_paused = true;//暂停投骰子bool m_stop = false;//停止线程protected:void run();//线程的任务public:void diceBegin();//开始掷骰子void dicePause();//暂停投骰子void stopThread();//停止线程signals:void newValue(int seq, int diceValue);//产生新点数的信号};

.cpp文件

#include "QtClass.h"
#include<QRandomGenerator>
#include<QThread>QtClass::QtClass(QObject *parent): QThread(parent)
{}
void QtClass::diceBegin() {//开始掷骰子m_paused = false;
}
void QtClass::dicePause() {//停止掷骰子m_paused = true;
}
void QtClass::stopThread() {//停止线程m_stop = true;
}
void QtClass::run() {//run函数处理事件循环m_stop = false;m_paused = true;m_seq = 0;while (!m_stop) {if (!m_paused) {m_diceValue = QRandomGenerator::global()->bounded(1, 7);m_seq++;emit newValue(m_seq, m_diceValue);}msleep(500);}quit();//退出线程
}
QtClass::~QtClass()
{}

http://www.hengruixuexiao.com/news/8628.html

相关文章:

  • 购物网站的建设时间游戏推广拉人渠道
  • 香港空间网站 备案爱站站长工具
  • 网站开发设计的地域分析nba湖人队最新消息
  • 跨境网站入口直接打开百度
  • 美食网站网页设计做一个简单网页
  • 页面好看的教育类网站模板下载百度首页登录
  • 铜仁公司做网站软文写作范例大全
  • 杭州设计企业网站高端公司百度推广时间段在哪里设置
  • 怎么在360网站做词条企业seo推广的绝密诀窍曝光
  • 外贸都是在哪些网站做百度浏览器官网下载并安装
  • 赣州人才网杭州专业seo公司
  • 如何鉴赏网站论文国产免费crm系统有哪些
  • 西安网站建设官网北京seo优化多少钱
  • 网站域名的作用长春百度推广公司
  • 珠海市网站建设分站怎么样百度号码认证平台取消标记
  • 网站建设签收单上海网站seo优化
  • 建网站网软文宣传推广
  • 可以申请做cpa广告的网站种子搜索在线 引擎
  • 建个企业网站需要多久网站seo诊断分析报告
  • 深圳专业做网站哪家好seo概念
  • 蓬莱做网站案例怎么做网络推广
  • 网站开发备案需要什么小说排行榜百度
  • autohome汽车之家官网网站关键词优化多少钱
  • 做磁力链网站安卓优化软件
  • 如何免费创建企业网站软文范例大全1000字
  • 成都哪家做网站网站开发报价方案
  • David网站做kegg分析步骤表白网站制作
  • 网页设计与网站建设步骤一句话宣传自己的产品
  • 免费网站申请江苏seo团队
  • 支付宝可以给第三方网站做担保么广告资源发布平台