PDA

View Full Version : QMessageBox crash when using QStyle::drawControl somewhere else



Kampfgnom
18th February 2013, 14:43
I have an odd problem.

I am using QStyle's drawControl() to draw a progress bar in a custom QStyledItemDelegate's paint().

Now the application crashes, when I try to open a QMessageBox with either show() or exec() or whatever.

I am quite sure, that this is not my fault and that it is exactly this combination.

I wrote a quite minimal example project, that shows the problem.

This is the delegate's paint() (the code has been taken from the documentation of QAbstractItemDelegate (http://qt-project.org/doc/qt-5.0/qtwidgets/qabstractitemdelegate.html#details)):


void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionProgressBar progressBarOption;
progressBarOption.rect = option.rect;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = index.data().toInt();

// This line crashes a QMessageBox. CE_ProgressBarContents and CE_ProgressBar lead to a crash.
// All other values of QStyle::CE_*** work fine.
// drawComplexControl has no problem either.
QApplication::style()->drawControl(QStyle::CE_ProgressBarContents, &progressBarOption, painter);
}


This is the main window constructor


m_model = new QStandardItemModel(this);

for(int i = 0; i < 10; ++i) {
QStandardItem *item = new QStandardItem(QString::number(i * 10));
m_model->appendRow(item);
}

ui->treeView->setModel(m_model);
ui->treeView->setItemDelegate(new ItemDelegate(this));

And this main() crashes:


MainWindow w;
w.show();

QMessageBox msgBox;
msgBox.show();

return a.exec();

This is the stacktrace:


0 QCoreApplication::notifyInternal 0x100bd50f0
1 QStyleAnimation::updateTarget 0x10009312f
2 QMacStyle::drawControl 0x100021169
3 QCommonStyle::drawControl 0x1000a0065
4 QMacStyle::drawControl 0x1000257f1
5 QPushButton::paintEvent 0x100194eea
6 QWidget::event 0x10006fece
7 QAbstractButton::event 0x1001073fd
8 QPushButton::event 0x100195841
9 QApplicationPrivate::notify_helper 0x1000397a7
10 QApplication::notify 0x10003ac0a
11 QCoreApplication::notifyInternal 0x100bd510e
12 QWidgetPrivate::drawWidget 0x10006ae8f
13 QWidgetPrivate::paintSiblingsRecursive 0x10006b6c4
14 QWidgetPrivate::drawWidget 0x10006b20f
15 QWidgetPrivate::paintSiblingsRecursive 0x10006b6c4
16 QWidgetPrivate::drawWidget 0x10006b20f
17 QWidgetBackingStore::sync 0x1000449d6
18 QWidgetPrivate::syncBackingStore 0x100062cf7
19 QWidget::event 0x1000704bb
20 QMessageBox::event 0x10021849b
... <Mehr>


The example project can be found on my GitHub: https://github.com/Kampfgnom/QMessageBoxCrash

I am using Qt 5.0.1 on Mac OS X 10.8.2. Is this a Qt bug? How would you work around it?

Kampfgnom
18th February 2013, 20:58
Since I didn't get any replies in here or on stackoverflow, I filed a bug report: QTBUG-29748 (https://bugreports.qt-project.org/browse/QTBUG-29748)

alrawab
18th February 2013, 21:08
sorry wrong post

norobro
18th February 2013, 21:21
Your app works fine on Debian & Qt 5.0.1.

Kampfgnom
19th February 2013, 07:31
Thanks for the confirmation :-)

Since at one point in the stack trace QMacStyle::drawControl is called, I assumed that this issue is Mac only. I am quite the Sherlock :-)

Kampfgnom
21st February 2013, 17:13
This was in fact a Qt bug. It will be fixed in 5.0.2.