Important: Please read the Qt Code of Conduct -

Qt setStyleSheet background-image crash on ubuntu 18.04

  • Hello,
    I get this crashing bug when set an Image to background of customize Qwidget .
    here the code :

    _ui->lbStatusIcon->setStyleSheet("background: transparent;");
    _ui->lbAvatar->setStyleSheet("background: transparent;");
    _ui->lbDisplayName->setStyleSheet("background: transparent; color: white; font: bold 14px;");//1px solid gray
        _ui->lbNoteBg->setStyleSheet("background: transparent; border-image: url(:/wui/lync/images/bg_note_left.png) 0 0 0 0;");
        //border: 1px solid #8e72f3;
    //background: #8e72f3;
        _ui->leNote->setStyleSheet("QLineEdit#leNote{background: #8e72f3; border-top-left-radius: 0px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 0px; color: white; font: normal 12px; height: 23px;}");
    _ui->tbSettings2->setStyleSheet("QToolButton{background: transparent; border-image: url(:/wui/lync/images/btn_settings_white.png)}");
        _ui->tbUpdateIndicator->setStyleSheet("QToolButton{background: transparent; border-image: url(:/wui/lync/images/btn_update_indicator.png)}");
     QString bgUrl = WApp::instance()->resource()->contactListHeaderBackground();//here is png image
    ==>>crash here ==>> this->setStyleSheet(QString("WContactListHeaderWidget{background-image: url(%1)}").arg(bgUrl));

    the custom widget contains some button, icon and background is an image which has size 3500 bytes, the size of image button about 315 bytes.
    setStyleSheet with small size (316 bytes) worked fine but crashing bug appears when size too big (>3500 bytes)
    here the backtrace :

    #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
    #1  0x00007ffff3ec1801 in __GI_abort () at abort.c:79
    #2  0x00007ffff3f14a91 in __malloc_assert (file=<optimized out>, function=<optimized out>, 
        line=<optimized out>, assertion=<optimized out>) at malloc.c:298
    #3  sysmalloc (nb=nb@entry=1264, av=av@entry=0x7ffff426cc40 <main_arena>) at malloc.c:2398
    #4  0x00007ffff3f15ff0 in _int_malloc (av=av@entry=0x7ffff426cc40 <main_arena>, bytes=bytes@entry=1256)
        at malloc.c:4125
    #5  0x00007ffff3f182ed in __GI___libc_malloc (bytes=1256) at malloc.c:3065
    #6  0x00007fffeeacfeb2 in png_malloc_warn () from /usr/lib/x86_64-linux-gnu/
    #7  0x00007fffeeac9f70 in ?? () from /usr/lib/x86_64-linux-gnu/
    #8  0x00007fffeead343d in png_create_read_struct_2 () from /usr/lib/x86_64-linux-gnu/
    #9  0x00007fffeead3491 in png_create_read_struct () from /usr/lib/x86_64-linux-gnu/
    #10 0x00007ffff5abbd56 in ?? () from /usr/lib/x86_64-linux-gnu/
    #11 0x00007ffff5abc0d6 in ?? () from /usr/lib/x86_64-linux-gnu/
    #12 0x00007ffff5abdb44 in ?? () from /usr/lib/x86_64-linux-gnu/
    #13 0x00007ffff5a76e73 in QImageReader::read(QImage*) () from /usr/lib/x86_64-linux-gnu/
    #14 0x00007ffff5a774d4 in QImageReader::read() () from /usr/lib/x86_64-linux-gnu/
    #15 0x00007ffff5a96fbd in QPlatformPixmap::fromFile(QString const&, char const*, QFlags<Qt::ImageConversionFlag>) () from /usr/lib/x86_64-linux-gnu/
    #16 0x00007ffff5a8f33a in QPixmap::load(QString const&, char const*, QFlags<Qt::ImageConversionFlag>) ()
       from /usr/lib/x86_64-linux-gnu/
    #17 0x00007ffff5a8f570 in QPixmap::QPixmap(QString const&, char const*, QFlags<Qt::ImageConversionFlag>) ()
       from /usr/lib/x86_64-linux-gnu/
    #18 0x00007ffff626ceae in ?? () from /usr/lib/x86_64-linux-gnu/
    #19 0x00007ffff626dcd6 in ?? () from /usr/lib/x86_64-linux-gnu/
    #20 0x00007ffff626fa8a in ?? () from /usr/lib/x86_64-linux-gnu/
    #21 0x00007ffff62728bf in ?? () from /usr/lib/x86_64-linux-gnu/
    #22 0x00007ffff6271a0f in ?? () from /usr/lib/x86_64-linux-gnu/
    #23 0x00007ffff6271b38 in ?? () from /usr/lib/x86_64-linux-gnu/
    #24 0x00007ffff61ff097 in QWidgetPrivate::inheritStyle() () from /usr/lib/x86_64-linux-gnu/
    #25 0x00007ffff61fef08 in QWidgetPrivate::setStyle_helper(QStyle*, bool, bool) ()
       from /usr/lib/x86_64-linux-gnu/

    dpkg --list|grep "libqt"

    ii  libqt5core5a:amd64                         5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 core module
    ii  libqt5dbus5:amd64                          5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 D-Bus module
    ii  libqt5gui5:amd64                           5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 GUI module
    ii  libqt5multimedia5:amd64                    5.9.5-0ubuntu1                               amd64        Qt 5 Multimedia module
    ii  libqt5multimediawidgets5:amd64             5.9.5-0ubuntu1                               amd64        Qt 5 Multimedia Widgets module
    ii  libqt5network5:amd64                       5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 network module
    ii  libqt5opengl5:amd64                        5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 OpenGL module
    ii  libqt5positioning5:amd64                   5.9.5+dfsg-0ubuntu2                          amd64        Qt Positioning module
    ii  libqt5printsupport5:amd64                  5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 print support module
    ii  libqt5qml5:amd64                           5.9.5-0ubuntu1.1                             amd64        Qt 5 QML module
    ii  libqt5quick5:amd64                         5.9.5-0ubuntu1.1                             amd64        Qt 5 Quick library
    ii  libqt5script5:amd64                        5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 script module
    ii  libqt5scripttools5:amd64                   5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 script tools module
    ii  libqt5sensors5:amd64                       5.9.5-0ubuntu1                               amd64        Qt Sensors module
    ii  libqt5sql5:amd64                           5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 SQL module
    ii  libqt5sql5-sqlite:amd64                    5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 SQLite 3 database driver
    ii  libqt5svg5:amd64                           5.9.5-0ubuntu1                               amd64        Qt 5 SVG module
    ii  libqt5webchannel5:amd64                    5.9.5-0ubuntu1                               amd64        Web communication library for Qt
    ii  libqt5webkit5:amd64                        5.212.0~alpha2-7ubuntu1                      amd64        Web content engine library for Qt
    ii  libqt5widgets5:amd64                       5.9.5+dfsg-0ubuntu1                          amd64        Qt 5 widgets module

    This crashing bug only appears on ubuntu 18.04 (16.04 work fine). I spent many days to searching the solution. Please help me

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From the looks of it, you are using your distribution Qt 5, is that correct ?
    It looks like the crash is in your installed libpng, what version is that ?

  • @SGaist Thank you for reply
    Yes, I use distribution Qt5
    My libpng version is libpng16 (version 1.6.34) for ubuntu 18.04

  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows the behaviour ?

Log in to reply