34 lines
1.1 KiB
C++
34 lines
1.1 KiB
C++
#ifndef QCORE_H
|
|
#define QCORE_H
|
|
#include <QThread>
|
|
|
|
inline QString byteSizeStr(double size) {
|
|
const char *units[]{"B", "KB", "MB", "GB", "TB", "PB"};
|
|
auto i = 0;
|
|
for(; size >= 1024 && i < 5; i++) size /= 1024;
|
|
return QString::number(size, 'g', 3)+" "+units[i];
|
|
}
|
|
|
|
inline long long steady_milli() {
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
|
}
|
|
inline long long system_milli() {
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|
|
inline long long steady_micro() {
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
|
}
|
|
inline long long system_micro() {
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|
|
|
|
template <typename Func>
|
|
inline QThread *ThreadStart(Func &&f) {
|
|
QThread* thread = QThread::create(f);
|
|
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
|
thread->start();
|
|
return thread;
|
|
}
|
|
|
|
#endif
|