目的
主要是讲解QTimer 与 QThread 结合时候, 容易出现各种各样警告, 如下
- QObject::startTimer: Timers cannot be started from another thread
- QObject::startTimer: Timers cannot be stopped from another thread
- Timers can only be used with threads started with QThread
目前来说经常遇到如上三条, 后面如有遇到我再补上。
demo 代码
cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QEventLoop>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
TestRun::TestRun(QObject *parent)
{
}
TestRun::~TestRun()
{