实验说明: 将一个循环放到线程里运行,同时将信息显示在主界面上,使得主界面不卡。
1 main.cpp
#include <QtGui/QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}2 dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QThread>
#include <QtCore>
#include <QtGui>
#include"mythread.h"
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private slots:
void on_StartPthread_clicked();
void on_St
这篇博客介绍如何在Qt环境中使用QThread进行线程操作,通过将循环任务放入线程来避免阻塞主界面,实现界面的流畅运行。详细内容包括main.cpp文件的编写以及最终的运行效果展示。
订阅专栏 解锁全文
1876

被折叠的 条评论
为什么被折叠?



