forked from qt-creator/qt-creator
SettingsDialog: Use RAII for event loops
With a custom deleter the event loop is exiting. The erase function is defining the order of deletion. Change-Id: I50cb166c4e117cbb779db2d1b992221cd1d8ad60 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Marco Bubke
parent
851726aad3
commit
a7e2c4595a
@@ -59,6 +59,13 @@
|
|||||||
static const char pageKeyC[] = "General/LastPreferencePage";
|
static const char pageKeyC[] = "General/LastPreferencePage";
|
||||||
const int categoryIconSize = 24;
|
const int categoryIconSize = 24;
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template<>
|
||||||
|
struct default_delete<QEventLoop> {
|
||||||
|
void operator()(QEventLoop* p) { p->exit(); delete p; } // exit event loop
|
||||||
|
};
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -426,10 +433,10 @@ private:
|
|||||||
Utils::FancyLineEdit *m_filterLineEdit;
|
Utils::FancyLineEdit *m_filterLineEdit;
|
||||||
QListView *m_categoryList;
|
QListView *m_categoryList;
|
||||||
QLabel *m_headerLabel;
|
QLabel *m_headerLabel;
|
||||||
|
std::vector<std::unique_ptr<QEventLoop>> m_eventLoops;
|
||||||
bool m_running = false;
|
bool m_running = false;
|
||||||
bool m_applied = false;
|
bool m_applied = false;
|
||||||
bool m_finished = false;
|
bool m_finished = false;
|
||||||
QList<QEventLoop *> m_eventLoops;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static QPointer<SettingsDialog> m_instance = nullptr;
|
static QPointer<SettingsDialog> m_instance = nullptr;
|
||||||
@@ -724,13 +731,8 @@ void SettingsDialog::done(int val)
|
|||||||
|
|
||||||
ICore::saveSettings(); // save all settings
|
ICore::saveSettings(); // save all settings
|
||||||
|
|
||||||
// exit all additional event loops, see comment in execDialog()
|
|
||||||
QListIterator<QEventLoop *> it(m_eventLoops);
|
m_eventLoops.erase(m_eventLoops.begin(), m_eventLoops.end()); // exit event loops in reverse order of addition
|
||||||
it.toBack();
|
|
||||||
while (it.hasPrevious()) {
|
|
||||||
QEventLoop *loop = it.previous();
|
|
||||||
loop->exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
QDialog::done(val);
|
QDialog::done(val);
|
||||||
}
|
}
|
||||||
@@ -759,9 +761,8 @@ bool SettingsDialog::execDialog()
|
|||||||
// a break point it will complain about missing helper, and offer the
|
// a break point it will complain about missing helper, and offer the
|
||||||
// option to open the settings dialog.
|
// option to open the settings dialog.
|
||||||
// Keep the UI running by creating another event loop.
|
// Keep the UI running by creating another event loop.
|
||||||
QEventLoop *loop = new QEventLoop(this);
|
m_eventLoops.emplace(m_eventLoops.begin(), std::make_unique<QEventLoop>());
|
||||||
m_eventLoops.append(loop);
|
m_eventLoops.front()->exec();
|
||||||
loop->exec();
|
|
||||||
}
|
}
|
||||||
return m_applied;
|
return m_applied;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user