Skip to content

Commit a77e847

Browse files
committed
Fix random crashes
1 parent 424a0e6 commit a77e847

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/qt/qt_machinestatus.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ MachineStatus::MachineStatus(QObject *parent)
257257
, refreshTimer(new QTimer(this))
258258
{
259259
d = std::make_unique<MachineStatus::States>(this);
260+
muteUnmuteAction = nullptr;
260261
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
261262
refreshTimer->start(75);
262263
}
@@ -502,7 +503,7 @@ MachineStatus::refresh(QStatusBar *sbar)
502503
sbar->removeWidget(d->sound.get());
503504

504505
if (!muteUnmuteAction) {
505-
muteUnmuteAction = new QAction(this);
506+
muteUnmuteAction = new QAction;
506507
connect(muteUnmuteAction, &QAction::triggered, this, [this]() {
507508
sound_muted ^= 1;
508509
if (d->sound)
@@ -513,11 +514,13 @@ MachineStatus::refresh(QStatusBar *sbar)
513514
}
514515

515516
if (!soundMenu) {
516-
soundMenu = new QMenu(sbar);
517+
soundMenu = new QMenu((QWidget*)parent());
517518

518519
soundMenu->addAction(muteUnmuteAction);
519520
soundMenu->addSeparator();
520521
soundMenu->addAction(soundGainAction);
522+
523+
muteUnmuteAction->setParent(soundMenu);
521524
}
522525

523526
if (cassette_enable) {
@@ -689,7 +692,8 @@ MachineStatus::refresh(QStatusBar *sbar)
689692

690693
d->sound = std::make_unique<ClickableLabel>();
691694
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
692-
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
695+
if (muteUnmuteAction)
696+
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
693697

694698
connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) {
695699
this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height()));

0 commit comments

Comments
 (0)