Results 1 to 6 of 6

Thread: QMessageBox crash when using QStyle::drawControl somewhere else

  1. #1
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QMessageBox crash when using QStyle::drawControl somewhere else

    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):

    Qt Code:
    1. void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QStyleOptionProgressBar progressBarOption;
    4. progressBarOption.rect = option.rect;
    5. progressBarOption.minimum = 0;
    6. progressBarOption.maximum = 100;
    7. progressBarOption.progress = index.data().toInt();
    8.  
    9. // This line crashes a QMessageBox. CE_ProgressBarContents and CE_ProgressBar lead to a crash.
    10. // All other values of QStyle::CE_*** work fine.
    11. // drawComplexControl has no problem either.
    12. QApplication::style()->drawControl(QStyle::CE_ProgressBarContents, &progressBarOption, painter);
    13. }
    To copy to clipboard, switch view to plain text mode 

    This is the main window constructor

    Qt Code:
    1. m_model = new QStandardItemModel(this);
    2.  
    3. for(int i = 0; i < 10; ++i) {
    4. QStandardItem *item = new QStandardItem(QString::number(i * 10));
    5. m_model->appendRow(item);
    6. }
    7.  
    8. ui->treeView->setModel(m_model);
    9. ui->treeView->setItemDelegate(new ItemDelegate(this));
    To copy to clipboard, switch view to plain text mode 

    And this main() crashes:

    Qt Code:
    1. MainWindow w;
    2. w.show();
    3.  
    4. QMessageBox msgBox;
    5. msgBox.show();
    6.  
    7. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    This is the stacktrace:
    Qt Code:
    1. 0 QCoreApplication::notifyInternal 0x100bd50f0
    2. 1 QStyleAnimation::updateTarget 0x10009312f
    3. 2 QMacStyle::drawControl 0x100021169
    4. 3 QCommonStyle::drawControl 0x1000a0065
    5. 4 QMacStyle::drawControl 0x1000257f1
    6. 5 QPushButton::paintEvent 0x100194eea
    7. 6 QWidget::event 0x10006fece
    8. 7 QAbstractButton::event 0x1001073fd
    9. 8 QPushButton::event 0x100195841
    10. 9 QApplicationPrivate::notify_helper 0x1000397a7
    11. 10 QApplication::notify 0x10003ac0a
    12. 11 QCoreApplication::notifyInternal 0x100bd510e
    13. 12 QWidgetPrivate::drawWidget 0x10006ae8f
    14. 13 QWidgetPrivate::paintSiblingsRecursive 0x10006b6c4
    15. 14 QWidgetPrivate::drawWidget 0x10006b20f
    16. 15 QWidgetPrivate::paintSiblingsRecursive 0x10006b6c4
    17. 16 QWidgetPrivate::drawWidget 0x10006b20f
    18. 17 QWidgetBackingStore::sync 0x1000449d6
    19. 18 QWidgetPrivate::syncBackingStore 0x100062cf7
    20. 19 QWidget::event 0x1000704bb
    21. 20 QMessageBox::event 0x10021849b
    22. ... <Mehr>
    To copy to clipboard, switch view to plain text mode 


    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?
    Last edited by Kampfgnom; 18th February 2013 at 14:57.

  2. #2
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMessageBox crash when using QStyle::drawControl somewhere else

    Since I didn't get any replies in here or on stackoverflow, I filed a bug report: QTBUG-29748

  3. #3
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMessageBox crash when using QStyle::drawControl somewhere else

    sorry wrong post

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QMessageBox crash when using QStyle::drawControl somewhere else

    Your app works fine on Debian & Qt 5.0.1.
    Attached Images Attached Images

  5. #5
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMessageBox crash when using QStyle::drawControl somewhere else

    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 :-)

  6. #6
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMessageBox crash when using QStyle::drawControl somewhere else

    This was in fact a Qt bug. It will be fixed in 5.0.2.

Similar Threads

  1. Replies: 2
    Last Post: 14th July 2011, 12:28
  2. Replies: 2
    Last Post: 9th June 2011, 11:20
  3. stylesheets and drawControl(CE_PushButton)
    By kochelmonster in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 22:26
  4. Replies: 2
    Last Post: 23rd May 2008, 13:22
  5. Stylesheeting and QStyle::drawControl() - possible?
    By dimuz in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2007, 08:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.