mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-14 02:52:03 +08:00
修复未发布版本打包器和wine下载工具的异线程修改UI的问题
This commit is contained in:
@@ -72,8 +72,9 @@ void DownloadThread::run(){
|
||||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
connect(reply, &QNetworkReply::downloadProgress, [=, &f, &t](qint64 bytesRead, qint64 totalBytes){
|
||||
f.write(reply->readAll());
|
||||
dialog->setValue((float)bytesRead / totalBytes * 100);
|
||||
dialog->setLabelText(QString::number(bytesRead / 1024 / 1024) + "MB/" + QString::number(totalBytes / 1024 / 1024) + "MB(在下载/安装时不要乱点程序、拖动程序,否则容易闪退)");
|
||||
emit ChangeDialog(dialog, (float)bytesRead / totalBytes * 100, bytesRead / 1024 / 1024, totalBytes / 1024 / 1024);
|
||||
//dialog->setValue();
|
||||
//dialog->setLabelText(QString::number(bytesRead / 1024 / 1024) + "MB/" + QString::number(totalBytes / 1024 / 1024) + "MB(在下载/安装时不要乱点程序、拖动程序,否则容易闪退)");
|
||||
if(t.isActive()){
|
||||
t.start(timeout);
|
||||
}
|
||||
@@ -84,6 +85,7 @@ void DownloadThread::run(){
|
||||
}
|
||||
loop.exec();
|
||||
if(reply->error() != QNetworkReply::NoError){
|
||||
qDebug() << "b";
|
||||
emit MessageBoxError("下载失败");
|
||||
f.close();
|
||||
delete reply;
|
||||
@@ -129,4 +131,5 @@ void DownloadThread::run(){
|
||||
process.start(QCoreApplication::applicationDirPath() + "/../launch.sh", command);
|
||||
process.waitForFinished();
|
||||
delete reply;
|
||||
emit Finish();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
class DownloadThread : public QThread // 继承 QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DownloadThread(QProgressDialog *dialog, QString url, QString save, QString fileName, QListView *view, bool deleteZip, bool unzip, QJsonArray *localList);
|
||||
void SettingVirtualMachine(QString savePath);
|
||||
@@ -32,6 +33,8 @@ signals:
|
||||
// 防止非主线程刷新控件导致程序退出
|
||||
void MessageBoxInfo(QString info);
|
||||
void MessageBoxError(QString info);
|
||||
void ChangeDialog(QProgressDialog *dialog, int value, int downloadBytes, int totalBytes);
|
||||
void Finish();
|
||||
};
|
||||
|
||||
#endif // DOWNLOADTHREAD_H
|
||||
|
||||
@@ -36,7 +36,19 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::MessageBoxInfo(QString info){
|
||||
QMessageBox::information(this, "提示", info);
|
||||
}
|
||||
void MainWindow::MessageBoxError(QString info){
|
||||
QMessageBox::critical(this, "错误", info);
|
||||
}
|
||||
void MainWindow::ChangeDialog(QProgressDialog *dialog, int value, int downloadBytes, int totalBytes){
|
||||
dialog->setValue(value);
|
||||
dialog->setLabelText(QString::number(downloadBytes) + "MB/" + QString::number(totalBytes) + "MB");
|
||||
}
|
||||
void MainWindow::DownloadFinish(){
|
||||
ui->centralWidget->setEnabled(true);
|
||||
}
|
||||
void MainWindow::on_addButton_clicked()
|
||||
{
|
||||
// 获取下载链接
|
||||
@@ -76,14 +88,13 @@ void MainWindow::on_addButton_clicked()
|
||||
!ui->unzip->isChecked(),
|
||||
&localJsonList
|
||||
);
|
||||
connect(thread, &DownloadThread::MessageBoxInfo, this, &MainWindow::MessageBoxInfo);
|
||||
connect(thread, &DownloadThread::MessageBoxError, this, &MainWindow::MessageBoxError);
|
||||
connect(thread, &DownloadThread::ChangeDialog, this, &MainWindow::ChangeDialog);
|
||||
connect(thread, &DownloadThread::Finish, this, &MainWindow::DownloadFinish);
|
||||
ui->centralWidget->setDisabled(true);
|
||||
thread->start();
|
||||
}
|
||||
void DownloadThread::MessageBoxInfo(QString info){
|
||||
QMessageBox::information(NULL, "提示", info);
|
||||
}
|
||||
void DownloadThread::MessageBoxError(QString info){
|
||||
QMessageBox::critical(NULL, "错误", info);
|
||||
}
|
||||
void MainWindow::ReadInternetInformation(){
|
||||
// 我们采用最简单的 curl 来获取信息
|
||||
QProcess internet;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QJsonArray>
|
||||
#include <QProgressDialog>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -26,6 +27,12 @@ private slots:
|
||||
|
||||
void on_delButton_clicked();
|
||||
|
||||
public slots:
|
||||
void MessageBoxInfo(QString info);
|
||||
void MessageBoxError(QString info);
|
||||
void ChangeDialog(QProgressDialog *dialog, int value, int downloadBytes, int totalBytes);
|
||||
void DownloadFinish();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user