close
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtConcurrent/QtConcurrentRun>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_pushButton_start_clicked();
void on_pushButton_stop_clicked();
private:
Ui::MainWindow *ui;
int counter;
bool running;
private:
void addCounter();
};
#endif // MAINWINDOW_H
void MainWindow::on_pushButton_start_clicked()
{
running = true;
QtConcurrent::run(this, &MainWindow::addCounter);
}
void MainWindow::addCounter()
{
while(running)
{
counter++;
ui->label->setText(QString::number(counter));
_sleep(100);
}
}
void MainWindow::on_pushButton_stop_clicked()
{
running = false;
}
全站熱搜
留言列表