forked from Dushistov/qt_monkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cpp
46 lines (41 loc) · 1.23 KB
/
common.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
#include "common.hpp"
#include <chrono>
#include <QWidget>
#include <QLabel>
#include <QCoreApplication>
QString qt_monkey_common::processErrorToString(QProcess::ProcessError err)
{
switch (err) {
case QProcess::FailedToStart:
return T_("Process failed to start");
case QProcess::Crashed:
return T_("Process crashed");
default:
return T_("Unknown error process error");
}
}
void qt_monkey_common::processEventsFor(int timeoutMs)
{
// QElapsedTimer occure only since Qt 4.7, so use chrono instead
auto startTime = std::chrono::steady_clock::now();
do {
qApp->processEvents(QEventLoop::AllEvents, 10 /*ms*/);
} while (std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - startTime)
< std::chrono::milliseconds(timeoutMs));
}
QString qt_monkey_common::searchMaxTextInWidget(QWidget &wdg)
{
auto labels = wdg.findChildren<QLabel *>();
if (auto lbl = qobject_cast<QLabel *>(&wdg)) {
labels.append(lbl);
}
QString max_cap;
for (const auto &lbl : labels) {
auto txt = lbl->text();
if (txt.length() > max_cap.length()) {
max_cap = txt;
}
}
return max_cap;
}