-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmainwindow.cpp
51 lines (44 loc) · 1.23 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "mainwindow.h"
#include "logasync.h"
#include <QtConcurrent>
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
auto *log = LogAsync::instance();
log->setLogPath(QDir::tempPath());
log->setAutoDelFile(true);
log->setAutoDelFileDays(7);
log->setOrientation(LogAsync::Orientation::StdAndFile);
log->setLogLevel(QtDebugMsg);
log->startWork();
auto *textBrowser = new QTextBrowser(this);
connect(log, &LogAsync::appendBuf, textBrowser, &QTextBrowser::append);
setCentralWidget(textBrowser);
resize(1000, 618);
qDebug() << "Start Log!";
m_watcher = QtConcurrent::run(&MainWindow::testLog, this);
}
MainWindow::~MainWindow()
{
m_running = false;
if (m_watcher.isRunning()) {
m_watcher.cancel();
m_watcher.waitForFinished();
}
LogAsync::instance()->stop();
qDebug() << "Stop Log!";
}
void MainWindow::testLog()
{
QElapsedTimer timer;
timer.start();
for (int i = 0; i < 1000; i++) {
if (!m_running) {
break;
}
qInfo() << "1234567890qwertyuiopasdfghjklzxcvbnm" << i;
QThread::msleep(1); //主界面无响应,上下文切换太快
}
qInfo() << timer.elapsed();
}