Why does Qt crash when loading a window icon?
c++, qt, ubuntu
Solution
I have also encountered this. The reason is the icon is too large. Resize to something smaller, 256x256 for example.
Problem
The following application crashes on `mainWindow->show();` ``` #include <QApplication> #include <QFrame> #include <QPixmap> int main(int argc, char *argv[]) { QApplication a(argc, argv); Q_INIT_RESOURCE(resources); QPixmap pix; pix.load(":/resources/images/app/icon_glow.png"); QFrame *mainWindow = new QFrame; mainWindow->setWindowIcon(QIcon(pix)); mainWindow->show(); return a.exec(); } ``` With the `mainWindow->setWindowIcon(QIcon(pix));` commented out, everything works. Otherwise, the backtrace (SEGFAULT, trying to dereference 0x8; seems like a missing nullptr check somewhere) is: ``` 0 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf4991138 1 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf4982d4c 2 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf498e7e3 3 ?? /usr/local/Qt32/5.3/gcc/plugins/platforms/libqxcb.so 0xf498f0f4 4 QWindowPrivate::applyCursor() /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf7517942 5 QWindowPrivate::setCursor(QCursor const*) /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf75179f7 6 QWindow::setCursor(QCursor const&) /usr/local/Qt32/5.3/gcc/lib/libQt5Gui.so.5 0xf7517b16 7 ?? /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7ad5d65 8 QWidgetPrivate::show_sys() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7ad60b6 9 QWidgetPrivate::show_helper() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7abab35 10 QWidget::setVisible(bool) /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7abb005 11 QWidget::show() /usr/local/Qt32/5.3/gcc/lib/libQt5Widgets.so.5 0xf7aad77e 12 main main.cpp 17 0x804a21f ``` I tried loading the resource as follows: ``` QLabel *mainLabel = new QLabel; mainLabel->setPixmap(pix); mainLabel->show(); ``` That works without a problem. Any help is greatly appreciated. Ubuntu 14.04 x64, compiled 32 bit, Qt 5.3 UPDATE: I reinstalled ubuntu-desktop (i reverted the desktop from 32 bit to 64 bit) and now I get an error: ``` The X11 connection broke: Maximum allowed requested length exceeded (code 4) XIO: fatal IO error 2 (No such file or directory) on X server ":0" after 409 requests (409 known processed) with 0 events remaining. ```