Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.5.1, 5.6.0 Beta
-
None
-
Linux
Description
As of qtbase's commit afaa7351c0f7f19c86796e9e48e2d16dbf5e4aa9, the following code segfaults at exit because the QSvgIconEngine is unloaded before the foo's QIcon::~QIcon() runs. At destruction time, ~QIcon accesses QIconPrivate::engine which is now a dangling pointer. It was fun to debug, valgrind didn't help much.
#include <QGuiApplication> #include <QIcon> static QIcon foo; int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); foo = QIcon(QStringLiteral("/usr/share/icons/bibletime.svg")); return 0; }
Using static instances of QIcon (or some other structures involving QIcon) is a common pattern when once comes around to implementing an icon cache to save some disk accesses. In my case, it was driven by a profiler's output.
As a client-side workaround, one can do something like this:
QIcon getIcon(...) { static QMap<QString, QIcon> cache; // static to make just one connection static auto conn = QObject::connect(qApp, &QCoreApplication::aboutToQuit, [](){ cache.clear(); }); // ... do something useful here return cache[...];
Please note that this is unrelated to the use of QStringLiteral; the code breaks in the exact same way if we use QString::fromUtf8.
Thiago's patch at https://codereview.qt-project.org/140750/ should fix this. QTBUG-27005 is a report against Qt 5.0.0 about this very same problem (but with a bit more complicated minimal reproducible example).
Crash visible only in Debugger
Attachments
Issue Links
- is replaced by
-
QTBUG-49061 QString static finalization SEGFAULT with use of QStringLiteral
- Closed