Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 1e769b5

Browse files
committed
Fix potential GUI instability due to GUI elements being called in worker
thread (thanks @maxnet) - see comments on 5d4d793 for details.
1 parent 5d4d793 commit 1e769b5

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

output

recovery/initdrivethread.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,12 @@ bool InitDriveThread::method_resizePartitions()
185185

186186
// Warn user that their SD card does not have an MBR and ask
187187
// if they would like us to create one for them
188-
QMessageBox msgBox;
189-
msgBox.setWindowTitle("Error: No MBR present on SD Card");
190-
msgBox.setText("Would you like NOOBS to create one for you?\nWARNING: This will erase all data on your SD card");
191-
msgBox.setStandardButtons(QMessageBox::Yes);
192-
msgBox.setDefaultButton(QMessageBox::No);
188+
QMessageBox::StandardButton answer;
189+
emit query(tr("Would you like NOOBS to create one for you?\nWARNING: This will erase all data on your SD card"),
190+
tr("Error: No MBR present on SD Card"),
191+
&answer);
193192

194-
if(msgBox.exec() == QMessageBox::Yes)
193+
if(answer == QMessageBox::Yes)
195194
{
196195

197196
emit statusUpdate(tr("Zeroing partition table"));

recovery/initdrivethread.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include <QThread>
14+
#include <QMessageBox>
1415
#include "config.h"
1516

1617
class InitDriveThread : public QThread
@@ -42,7 +43,7 @@ class InitDriveThread : public QThread
4243
void error(const QString &msg);
4344
void statusUpdate(const QString &msg);
4445
void completed();
45-
46+
void query(const QString &msg, const QString &title, QMessageBox::StandardButton* answer);
4647

4748
public slots:
4849

recovery/mainwindow.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ MainWindow::MainWindow(QString *currentLangCode, QSplashScreen *splash, Language
7171
connect(idt, SIGNAL(statusUpdate(QString)), _qpd, SLOT(setLabelText(QString)));
7272
connect(idt, SIGNAL(completed()), _qpd, SLOT(deleteLater()));
7373
connect(idt, SIGNAL(error(QString)), this, SLOT(onError(QString)));
74+
connect(idt, SIGNAL(query(QString, QString, QMessageBox::StandardButton*)),
75+
this, SLOT(onQuery(QString, QString, QMessageBox::StandardButton*)),
76+
Qt::BlockingQueuedConnection);
7477

7578
idt->start();
7679
_qpd->exec();
@@ -321,6 +324,13 @@ void MainWindow::onError(const QString &msg)
321324
setEnabled(true);
322325
}
323326

327+
void MainWindow::onQuery(const QString &msg, const QString &title, QMessageBox::StandardButton* answer)
328+
{
329+
_qpd->hide();
330+
*answer = QMessageBox::question(this, title, msg, QMessageBox::Yes|QMessageBox::No);
331+
setEnabled(true);
332+
}
333+
324334
void MainWindow::on_list_currentRowChanged()
325335
{
326336
ui->actionWrite_image_to_disk->setEnabled(true);

recovery/mainwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QMainWindow>
1515
#include <QModelIndex>
1616
#include <QSplashScreen>
17+
#include <QMessageBox>
1718

1819
namespace Ui {
1920
class MainWindow;
@@ -58,6 +59,7 @@ protected slots:
5859
/* Events from ImageWriterThread */
5960
void onError(const QString &msg);
6061
void onCompleted();
62+
void onQuery(const QString &msg, const QString &title, QMessageBox::StandardButton* answer);
6163

6264
private slots:
6365
/* UI events */

0 commit comments

Comments
 (0)