#ifndef QCORE_H #define QCORE_H #include #include #include #define ToStr QString::number inline QString toStr(int num, int base=10) {return QString::number(num, base);} inline QString toStr(uint num, int base=10) {return QString::number(num, base);} inline QString toStr(long num, int base=10) {return QString::number(num, base);} inline QString toStr(ulong num, int base=10) {return QString::number(num, base);} inline QString toStr(qlonglong num, int base=10) {return QString::number(num, base);} inline QString toStr(qulonglong num, int base=10) {return QString::number(num, base);} inline QString toStr(double num, char format='g', int precision=6) {return QString::number(num, format, precision);} inline QString gUrlSuffix(const QString &url, int size, bool withDot = false) { auto ss = url.lastIndexOf('/')+1; if(ss==url.size()) return QString(); ss++; auto ee = url.indexOf('?', ss); if(ee==-1) ee = url.size(); int end = ee-size-1; if(end=end; --i) if(url[i]=='.') return withDot ? url.mid(i, ee-i) : url.mid(i+1, ee-i-1); return QString(); } 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 void wait(int msec, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents) { QTimer timer; timer.setSingleShot(true); QEventLoop loop; QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); timer.start(msec); loop.exec(flags); } template inline QThread *ThreadStart(Func &&f) { QThread* thread = QThread::create(f); QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater); thread->start(); return thread; } #endif