diff options
author | Gerald Combs <gerald@wireshark.org> | 2017-11-20 09:18:59 -0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2017-11-20 22:08:09 +0000 |
commit | dd562b503f2ff089968283b1593496c007f854a6 (patch) | |
tree | dcdfbd93a1f7dbaa11761915dfdfcf58beb0d00c /ui | |
parent | 5968fc1cae5028002d4f974e0464608f73204b60 (diff) |
Qt: Move the MIME init thread to WiresharkApplication.
The Qt 4.8 "Starting a Thread" document at
http://doc.qt.io/qt-4.8/threads-starting.html says,
"Note that you must create the QApplication (or QCoreApplication) object
before you can create a QThread."
It looks like this changed some time around Qt 5.5 or 5.6, e.g.
https://codereview.qt-project.org/#/c/120793/, but just to be safe move
the MIME database initialization thread to WiresharkApplication. We
start reading the database later than I'd like, but it's still early
enough to make a difference here.
QMimeDatabase was added in Qt 5.0. Add version checks.
Change-Id: Ic80ebb8692e93b1e4aea7a8670f4fcf45e385b29
Reviewed-on: https://code.wireshark.org/review/24512
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/wireshark_application.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 6abd29e4df..4f30f55d6a 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -93,11 +93,15 @@ #include <QMainWindow> #include <QMutableListIterator> #include <QSocketNotifier> -#include <QThread> #include <QUrl> #include <QColorDialog> #include <qmath.h> +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#include <QMimeDatabase> +#include <QThreadPool> +#endif + #ifdef _MSC_VER #pragma warning(pop) #endif @@ -115,6 +119,22 @@ static QHash<int, QList<QAction *> > removed_menu_groups_; QString WiresharkApplication::window_title_separator_ = QString::fromUtf8(" " UTF8_MIDDLE_DOT " "); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + +// QMimeDatabase parses a large-ish XML file and can be slow to initialize. +// Do so in a worker thread as early as possible. +// https://github.com/lxde/pcmanfm-qt/issues/415 +class MimeDatabaseInitThread : public QRunnable +{ +private: + void run() + { + QMimeDatabase mime_db; + mime_db.mimeTypeForData(QByteArray()); + } +}; +#endif + void topic_action(topic_action_e action) { @@ -438,9 +458,6 @@ void WiresharkApplication::reloadLuaPluginsDelayed() QTimer::singleShot(0, this, SIGNAL(reloadLuaPlugins())); } -// This should be the first icon we fetch. We delay loading it as much as -// possible in order to allow time for MimeDatabaseInitThread in -// wireshark-qt.cpp to do its work. const QIcon &WiresharkApplication::normalIcon() { if (normal_icon_.isNull()) { @@ -731,6 +748,11 @@ WiresharkApplication::WiresharkApplication(int &argc, char **argv) : wsApp = this; setApplicationName("Wireshark"); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + MimeDatabaseInitThread *mime_db_init_thread = new(MimeDatabaseInitThread); + QThreadPool::globalInstance()->start(mime_db_init_thread); +#endif + Q_INIT_RESOURCE(about); Q_INIT_RESOURCE(i18n); Q_INIT_RESOURCE(layout); @@ -992,7 +1014,7 @@ void WiresharkApplication::clearDynamicMenuGroupItems() void WiresharkApplication::initializeIcons() { // Do this as late as possible in order to allow time for - // MimeDatabaseInitThread in wireshark-qt.cpp to do its work. + // MimeDatabaseInitThread to do its work. QList<int> icon_sizes = QList<int>() << 16 << 24 << 32 << 48 << 64 << 128 << 256 << 512 << 1024; foreach (int icon_size, icon_sizes) { QString icon_path = QString(":/wsicon/wsicon%1.png").arg(icon_size); |