Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QScrollArea causes crash on close()



  • Hello.
    In my application, I have a window with a QScrollArea, that contains some labels to be scrolled. Let's name it "ScrollForm". The ScrollForm can be shown from the main window.
    The problem is: if I close the ScrollForm using cross in the corner and then reopen it from the main window (using ScrollForm::show()), ScrollForm is not being rendered, and interacting with it causes application to crash. The debugger doesn't show anything useful, it crashes somewhere deep inside Qt.
    However, if I call ScrollForm::hide() and then ScrollForm::show(), everything works fine.
    I was able to make a workaround by caatching QCloseEvent and ignoring it, hiding ScrollForm instead. However, the Qt manual states that there's no difference between close() and hide() if Qt::WA_DeleteOnClose is disabled (which is the default).
    I've tried to disable Qt::WA_DeleteOnClose explicitly, but the behaviour is the same: calling close() and hide() breaks down the window.
    Here is the sample code. The commented blocks of code are a workaround:

    // scrollform.h
    #pragma once
    
    #include <QWidget>
    
    namespace Ui {
    class ScrollForm;
    }
    
    class ScrollForm : public QWidget
    {
      Q_OBJECT
    
    public:
      explicit ScrollForm(QWidget *parent = nullptr);
      ~ScrollForm();
    
    //protected:
    //  void closeEvent(QCloseEvent*);
    
    private:
      Ui::ScrollForm *ui;
    };
    
    // scrollform.cpp
    #include "scrollform.h"
    #include "ui_scrollform.h"
    #include <QVBoxLayout>
    #include <QLabel>
    #include <QCloseEvent>
    
    ScrollForm::ScrollForm(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::ScrollForm)
    {
      ui->setupUi(this);
      setAttribute(Qt::WA_DeleteOnClose, false);
    
      QWidget* w = new QWidget;
      w->setAttribute(Qt::WA_DeleteOnClose, false);
      ui->scrollArea->setWidget(w);
      ui->scrollArea->setAttribute(Qt::WA_DeleteOnClose, false);
    
      QVBoxLayout* vbl = new QVBoxLayout(w);
      vbl->setSizeConstraint(QLayout::SetMinAndMaxSize);
    
      for(int a=0; a<100; a++)
      {
        QLabel* l = new QLabel();
        l->setAttribute(Qt::WA_DeleteOnClose, false);
        l->setText(tr("This is a label number %1").arg(a+1));
        vbl->addWidget(l);
      }
    
    }
    
    ScrollForm::~ScrollForm()
    {
      delete ui;
    }
    
    //void ScrollForm::closeEvent(QCloseEvent *e)
    //{
    //  e->ignore();
    //  hide();
    //}
    

    Using Linux Mint 19.1 Qt 5.12, clang 6.0.0 or gcc 7.4.0
    However, using system-provided Qt 5.9 doesn't cause this bug. Everything works fine.


  • Qt Champions 2019

    What Qt5.12 version exactly? Can you show us the backtrace?



  • Qt version 5.12.4 GCC 64 bit

    Here is the call stack at the app crash (show, close, show, scroll with mouse wheel somewhere in an unpainted window).
    Everything except main.cpp is grayed out.

    1  QWidgetBackingStore::markDirtyOnScreen                 qwidgetbackingstore.cpp    727  0x7ffff76f67a3 
    2  QWidgetPrivate::moveRect                               qwidgetbackingstore.cpp    919  0x7ffff76f8ca1 
    3  QWidgetPrivate::setGeometry_sys                        qwidget.cpp                7351 0x7ffff771c6bd 
    4  QWidget::move                                          qwidget.cpp                7182 0x7ffff771c974 
    5  QWidget::move                                          qwidget.h                  836  0x7ffff78679df 
    6  QScrollAreaPrivate::updateWidgetPosition               qscrollarea.cpp            181  0x7ffff78679df 
    7  QAbstractScrollAreaPrivate::_q_vslide                  qabstractscrollarea.cpp    1542 0x7ffff77cb311 
    8  QMetaObject::activate                                  qobject.cpp                3801 0x7ffff68404e9 
    9  QMetaObject::activate                                  qobject.cpp                3654 0x7ffff6840df7 
    10 QAbstractSlider::valueChanged                          moc_qabstractslider.cpp    308  0x7ffff77d058e 
    11 QAbstractSlider::setValue                              qabstractslider.cpp        546  0x7ffff77d0bc7 
    12 QAbstractSlider::triggerAction                         qabstractslider.cpp        635  0x7ffff77d0e02 
    13 QAbstractSliderPrivate::scrollByDelta                  qabstractslider.cpp        750  0x7ffff77d17f9 
    14 QScrollBar::wheelEvent                                 qscrollbar.cpp             509  0x7ffff7868c2c 
    15 QWidget::event                                         qwidget.cpp                9325 0x7ffff7724790 
    16 QAbstractSlider::event                                 qabstractslider.cpp        955  0x7ffff77d1955 
    17 QScrollBar::event                                      qscrollbar.cpp             490  0x7ffff786a8e2 
    18 QApplicationPrivate::notify_helper                     qapplication.cpp           3737 0x7ffff76e69ac 
    19 QApplication::notify                                   qapplication.cpp           3290 0x7ffff76ef464 
    20 QCoreApplication::notifyInternal2                      qcoreapplication.cpp       1084 0x7ffff6814a28 
    21 QWidget::event                                         qwidget.cpp                9325 0x7ffff7724790 
    22 QFrame::event                                          qframe.cpp                 550  0x7ffff77c8e9e 
    23 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp       1210 0x7ffff68147bd 
    24 QApplicationPrivate::notify_helper                     qapplication.cpp           3731 0x7ffff76e6985 
    25 QApplication::notify                                   qapplication.cpp           3290 0x7ffff76ef464 
    26 QCoreApplication::notifyInternal2                      qcoreapplication.cpp       1084 0x7ffff6814a28 
    27 QCoreApplication::forwardEvent                         qcoreapplication.cpp       1099 0x7ffff6814a72 
    28 QWidgetWindow::handleWheelEvent                        qwidgetwindow.cpp          848  0x7ffff773f6a6 
    29 QWidgetWindow::event                                   qwidgetwindow.cpp          308  0x7ffff7740cd3 
    30 QApplicationPrivate::notify_helper                     qapplication.cpp           3737 0x7ffff76e69ac 
    31 QApplication::notify                                   qapplication.cpp           3483 0x7ffff76edaa0 
    32 QCoreApplication::notifyInternal2                      qcoreapplication.cpp       1084 0x7ffff6814a28 
    33 QCoreApplication::sendSpontaneousEvent                 qcoreapplication.cpp       1484 0x7ffff6814bee 
    34 QGuiApplicationPrivate::processWheelEvent              qguiapplication.cpp        2185 0x7ffff6e8b177 
    35 QGuiApplicationPrivate::processWindowSystemEvent       qguiapplication.cpp        1845 0x7ffff6e90115 
    36 QWindowSystemInterface::sendWindowSystemEvents         qwindowsysteminterface.cpp 1151 0x7ffff6e6d76b 
    37 xcbSourceDispatch                                      qxcbeventdispatcher.cpp    105  0x7ffff0a2ecba 
    38 g_main_context_dispatch                                                                0x7ffff28a4417 
    39 ??                                                                                     0x7ffff28a4650 
    40 g_main_context_iteration                                                               0x7ffff28a46dc 
    41 QEventDispatcherGlib::processEvents                    qeventdispatcher_glib.cpp  422  0x7ffff686be3f 
    42 QEventLoop::exec                                       qeventloop.cpp             225  0x7ffff68132ea 
    43 QCoreApplication::exec                                 qcoreapplication.cpp       1385 0x7ffff681bd30 
    44 main                                                   main.cpp                   10   0x403baa       
    
    

  • Qt Champions 2019

    @umod-47 said in QScrollArea causes crash on close():

    show, close, show, scroll

    Well-known problem with Qt5.12.3/.4 - upgrade to 5.12.5. See QTBUG-76588



  • @Christian-Ehrlicher
    Indeed, updating to 5.12.5 solved the problem. Thanks!


Log in to reply