⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadform.cpp

📁 这个是QT3C++编程书(齐亮翻译)里14,17,18章的代码
💻 CPP
字号:
#include <qlayout.h>#include <qpushbutton.h>#include "threadform.h"ThreadForm::ThreadForm(QWidget *parent, const char *name)    : QDialog(parent, name){    setCaption(tr("Threads"));    threadA.setMessage("A");    threadB.setMessage("B");    threadAButton = new QPushButton(tr("Start A"), this);    threadBButton = new QPushButton(tr("Start B"), this);    quitButton = new QPushButton(tr("Quit"), this);    quitButton->setDefault(true);    connect(threadAButton, SIGNAL(clicked()),            this, SLOT(startOrStopThreadA()));    connect(threadBButton, SIGNAL(clicked()),            this, SLOT(startOrStopThreadB()));    connect(quitButton, SIGNAL(clicked()),            this, SLOT(close()));    QHBoxLayout *mainLayout = new QHBoxLayout(this);    mainLayout->setResizeMode(QLayout::Fixed);    mainLayout->setMargin(11);    mainLayout->setSpacing(6);    mainLayout->addWidget(threadAButton);    mainLayout->addWidget(threadBButton);    mainLayout->addWidget(quitButton);}void ThreadForm::startOrStopThreadA(){    if (threadA.running()) {        threadA.stop();        threadAButton->setText(tr("Start A"));    } else {        threadA.start();        threadAButton->setText(tr("Stop A"));    }}void ThreadForm::startOrStopThreadB(){    if (threadB.running()) {        threadB.stop();        threadBButton->setText(tr("Start B"));    } else {        threadB.start();        threadBButton->setText(tr("Stop B"));    }}void ThreadForm::closeEvent(QCloseEvent *event){    threadA.stop();    threadB.stop();    threadA.wait();    threadB.wait();    event->accept();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -