Results 1 to 7 of 7

Thread: QStyledItemDelegate crash

  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QStyledItemDelegate crash

    I have a simple list to show list of plugins in my program. To customize it i use delegate class derived from QStyledItemDelegate.
    The code:
    Qt Code:
    1. class PluginListDelegate : public QStyledItemDelegate
    2. {
    3. public:
    4. PluginListDelegate();
    5. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    6. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const;
    7. private:
    8. QFont line1;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. PluginListDelegate::PluginListDelegate() :
    2. line1("Tahoma",10,QFont::Bold,false)
    3. {
    4.  
    5. }
    6. void PluginListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    7. {
    8. QStyledItemDelegate::paint(painter,option,index);
    9. ...
    10. ...
    11. }
    12.  
    13. QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    14. {
    15. int width = 0,height = 0;
    16. QFontMetrics fm1(line1); // <-- crash here
    17. height = fm1.height() + 20;
    18. width = fm1.width(name) + 20;
    19. return QSize(width,height);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Really don't understand what I do wrong.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStyledItemDelegate crash

    What is the actual backtrace?

  3. #3
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStyledItemDelegate crash

    SIGSEGV
    Segmentation fault

    it stoped at line 573 in qvariant.h

    Qt Code:
    1. static T metaType(const QVariant &v)
    2. {
    3. const int vid = qMetaTypeId<T>();
    4. if (vid == v.userType())
    5. return *reinterpret_cast<const T *>(v.constData()); // <-- stopped here
    6. if (vid < int(QMetaType::User)) {
    7. T t;
    8. if (v.convert(vid, &t))
    9. return t;
    10. }
    11. return T();
    12. }
    To copy to clipboard, switch view to plain text mode 
    I use Windows XP, Qt 5.1.0

    Hmm ... I found now that it crashed only when I debug the program with F5.
    If i run the program with Ctrl-R it works normally.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStyledItemDelegate crash

    Yes, all very well, but what is the actual backtrace? That will you how the program arrived there (which doesn't look related to your first location).

  5. #5
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStyledItemDelegate crash

    Where can I see this backtrace?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStyledItemDelegate crash

    When you run a debug build of your program in your debugger until it crashes. Then you can generally see the backtrace in your IDE. In Qt Creator the panel is called "Stack" and might contain something like this:
    Qt Code:
    1. 0 MainWindow::crashNow mainwindow.cpp 41 0x4030f3
    2. 1 MainWindow::doMoreStuff mainwindow.cpp 36 0x4030d8
    3. 2 MainWindow::doStuff mainwindow.cpp 31 0x4030be
    4. 3 MainWindow::qt_static_metacall moc_mainwindow.cpp 52 0x40370e
    5. 4 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6de1c01
    6. 5 ?? /usr/lib64/qt4/libQtCore.so.4 0x7ffff6deb3df
    7. 6 QObject::event(QEvent*) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6de6ba9
    8. 7 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib64/qt4/libQtGui.so.4 0x7ffff7306c04
    9. 8 QApplication::notify(QObject*, QEvent*) /usr/lib64/qt4/libQtGui.so.4 0x7ffff730b9d3
    10. 9 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dcdd9c
    11. 10 ?? /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dfedd2
    12. 11 ?? /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dfc70d
    13. 12 ?? /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dfc731
    14. 13 g_main_context_dispatch /usr/lib64/libglib-2.0.so.0 0x7ffff65683f2
    15. 14 ?? /usr/lib64/libglib-2.0.so.0 0x7ffff6568738
    16. 15 g_main_context_iteration /usr/lib64/libglib-2.0.so.0 0x7ffff65687f4
    17. 16 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dfcebf
    18. 17 ?? /usr/lib64/qt4/libQtGui.so.4 0x7ffff73a96fe
    19. 18 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dcc8d2
    20. 19 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dccb27
    21. 20 QCoreApplication::exec() /usr/lib64/qt4/libQtCore.so.4 0x7ffff6dd1945
    22. ... <More>
    To copy to clipboard, switch view to plain text mode 
    If you are using a different IDE or different debugger then the output might look different.

    The top line is the point of failure (in my example a divide-by-zero), The next line down is where it was called from, and so on. Keep going until you find the first line of your code...

  7. #7
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStyledItemDelegate crash

    Thank you, ChrisW67
    I will try it.
    It is strange but now I cant get to crash. It happened periodically before but now it runs without error both in debug and run modes ))

Similar Threads

  1. little problem with QStyledItemDelegate
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2012, 10:21
  2. Replies: 1
    Last Post: 19th June 2012, 21:20
  3. QTreeView & QStyledItemDelegate
    By mentalmushroom in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2011, 08:57
  4. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 11:32
  5. QStyledItemDelegate and QStyle::State_MouseOver
    By moti.lahiani in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 07:36

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.