diff --git a/VM-source/VirtualMachine b/VM-source/VirtualMachine index 462a193..a6375cb 100755 Binary files a/VM-source/VirtualMachine and b/VM-source/VirtualMachine differ diff --git a/VM-source/main.cpp b/VM-source/main.cpp index 19eb1a9..52c4ea7 100755 --- a/VM-source/main.cpp +++ b/VM-source/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) a.installTranslator(trans); // 判断是否为 !amd64 - if(GetRunCommand("arch").replace(" ", "").replace("\n", "") == QString("x86_64")){ + if(GetRunCommand("arch").replace(" ", "").replace("\n", "") != QString("x86_64")){ QMessageBox::critical(NULL, "错误", "此程序不支持非 X86 架构,立即退出"); return 0; } diff --git a/VM-source/main.o b/VM-source/main.o index 7ac6858..697fcb5 100644 Binary files a/VM-source/main.o and b/VM-source/main.o differ diff --git a/VM-source/mainwindow.cpp b/VM-source/mainwindow.cpp index b539944..73fd55e 100755 --- a/VM-source/mainwindow.cpp +++ b/VM-source/mainwindow.cpp @@ -12,6 +12,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -27,6 +28,37 @@ MainWindow::MainWindow(QWidget *parent) : system("xdg-open https://www.virtualbox.org/wiki/Linux_Downloads"); } } + // QTimer + QTimer *cpuGet = new QTimer(this); + connect(cpuGet, &QTimer::timeout, this, &MainWindow::ShowCPUMessage); + cpuGet->setInterval(600); + cpuGet->start(); +} + +void MainWindow::ShowCPUMessage(){ + // 获取 CPU 占用率 + long cpuAll = 0; + long cpuFree = 0; + infoUtils::cpuRate(cpuAll, cpuFree); + long cpu = ((cpuAll - m_cpuAll) - (cpuFree - m_cpuFree)) * 100 / (cpuAll - m_cpuAll); + if(cpu > 100){ + // 处理异常值 + cpu = 100; + } + // 获取内存占用率 + long memory = 0; + long memoryAll = 0; + long swap = 0; + long swapAll = 0; + + infoUtils::memoryRate(memory, memoryAll, swap, swapAll); + + QString info = "CPU: " + QString::number(cpu) + "% 内存: " + + QString::number(memory * 100 / memoryAll) + "% " + QString::number(memory / 1024) + "MB/" + QString::number(memoryAll / 1024) + "MB"; + qDebug() << cpuAll << " " << cpuFree; + ui->CPUValue->showMessage(info, 5000); + m_cpuAll = cpuAll; + m_cpuFree = cpuFree; } QString MainWindow::GetRunCommand(QString command){ diff --git a/VM-source/mainwindow.h b/VM-source/mainwindow.h index f4be400..70d9029 100755 --- a/VM-source/mainwindow.h +++ b/VM-source/mainwindow.h @@ -16,12 +16,16 @@ public: ~MainWindow(); private slots: + void ShowCPUMessage(); void on_browser_clicked(); QString GetRunCommand(QString command); void on_install_clicked(); + private: Ui::MainWindow *ui; + long m_cpuAll; + long m_cpuFree; }; #endif // MAINWINDOW_H diff --git a/VM-source/mainwindow.o b/VM-source/mainwindow.o index 4495669..4b31aa2 100644 Binary files a/VM-source/mainwindow.o and b/VM-source/mainwindow.o differ diff --git a/VM-source/mainwindow.ui b/VM-source/mainwindow.ui index 76f4722..e770de8 100755 --- a/VM-source/mainwindow.ui +++ b/VM-source/mainwindow.ui @@ -25,7 +25,7 @@ QTabWidget::Rounded - 2 + 1 @@ -306,6 +306,11 @@ p, li { white-space: pre-wrap; } + + + + + 退出 diff --git a/VM-source/moc_mainwindow.cpp b/VM-source/moc_mainwindow.cpp index 6b09864..a748ccb 100644 --- a/VM-source/moc_mainwindow.cpp +++ b/VM-source/moc_mainwindow.cpp @@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_MainWindow_t { - QByteArrayData data[6]; - char stringdata0[72]; + QByteArrayData data[7]; + char stringdata0[87]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ @@ -33,15 +33,17 @@ struct qt_meta_stringdata_MainWindow_t { static const qt_meta_stringdata_MainWindow_t qt_meta_stringdata_MainWindow = { { QT_MOC_LITERAL(0, 0, 10), // "MainWindow" -QT_MOC_LITERAL(1, 11, 18), // "on_browser_clicked" -QT_MOC_LITERAL(2, 30, 0), // "" -QT_MOC_LITERAL(3, 31, 13), // "GetRunCommand" -QT_MOC_LITERAL(4, 45, 7), // "command" -QT_MOC_LITERAL(5, 53, 18) // "on_install_clicked" +QT_MOC_LITERAL(1, 11, 14), // "ShowCPUMessage" +QT_MOC_LITERAL(2, 26, 0), // "" +QT_MOC_LITERAL(3, 27, 18), // "on_browser_clicked" +QT_MOC_LITERAL(4, 46, 13), // "GetRunCommand" +QT_MOC_LITERAL(5, 60, 7), // "command" +QT_MOC_LITERAL(6, 68, 18) // "on_install_clicked" }, - "MainWindow\0on_browser_clicked\0\0" - "GetRunCommand\0command\0on_install_clicked" + "MainWindow\0ShowCPUMessage\0\0" + "on_browser_clicked\0GetRunCommand\0" + "command\0on_install_clicked" }; #undef QT_MOC_LITERAL @@ -51,7 +53,7 @@ static const uint qt_meta_data_MainWindow[] = { 8, // revision 0, // classname 0, 0, // classinfo - 3, 14, // methods + 4, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -59,13 +61,15 @@ static const uint qt_meta_data_MainWindow[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags - 1, 0, 29, 2, 0x08 /* Private */, - 3, 1, 30, 2, 0x08 /* Private */, - 5, 0, 33, 2, 0x08 /* Private */, + 1, 0, 34, 2, 0x08 /* Private */, + 3, 0, 35, 2, 0x08 /* Private */, + 4, 1, 36, 2, 0x08 /* Private */, + 6, 0, 39, 2, 0x08 /* Private */, // slots: parameters QMetaType::Void, - QMetaType::QString, QMetaType::QString, 4, + QMetaType::Void, + QMetaType::QString, QMetaType::QString, 5, QMetaType::Void, 0 // eod @@ -77,10 +81,11 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, auto *_t = static_cast(_o); (void)_t; switch (_id) { - case 0: _t->on_browser_clicked(); break; - case 1: { QString _r = _t->GetRunCommand((*reinterpret_cast< QString(*)>(_a[1]))); + case 0: _t->ShowCPUMessage(); break; + case 1: _t->on_browser_clicked(); break; + case 2: { QString _r = _t->GetRunCommand((*reinterpret_cast< QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = std::move(_r); } break; - case 2: _t->on_install_clicked(); break; + case 3: _t->on_install_clicked(); break; default: ; } } @@ -115,13 +120,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 3) + if (_id < 4) qt_static_metacall(this, _c, _id, _a); - _id -= 3; + _id -= 4; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 3) + if (_id < 4) *reinterpret_cast(_a[0]) = -1; - _id -= 3; + _id -= 4; } return _id; } diff --git a/VM-source/moc_mainwindow.o b/VM-source/moc_mainwindow.o index ed70fda..73ac74f 100644 Binary files a/VM-source/moc_mainwindow.o and b/VM-source/moc_mainwindow.o differ diff --git a/VM-source/ui_mainwindow.h b/VM-source/ui_mainwindow.h index 1605c2c..3631b25 100644 --- a/VM-source/ui_mainwindow.h +++ b/VM-source/ui_mainwindow.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ public: QLabel *label_3; QSpacerItem *verticalSpacer_2; QTextBrowser *textBrowser_2; + QStatusBar *CPUValue; void setupUi(QMainWindow *MainWindow) { @@ -209,10 +211,13 @@ public: horizontalLayout->addWidget(tabWidget); MainWindow->setCentralWidget(centralWidget); + CPUValue = new QStatusBar(MainWindow); + CPUValue->setObjectName(QString::fromUtf8("CPUValue")); + MainWindow->setStatusBar(CPUValue); retranslateUi(MainWindow); - tabWidget->setCurrentIndex(2); + tabWidget->setCurrentIndex(1); QMetaObject::connectSlotsByName(MainWindow); @@ -353,6 +358,9 @@ public: "

https://juejin.cn/post/7080484519328874510

", nullptr)); tabWidget->setTabText(tabWidget->indexOf(tab_2), QCoreApplication::translate("MainWindow", "\345\205\263\344\272\216", nullptr)); +#if QT_CONFIG(statustip) + CPUValue->setStatusTip(QString()); +#endif // QT_CONFIG(statustip) } // retranslateUi };