Results 1 to 6 of 6

Thread: QWidget::paintEvent() behaviour

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWidget::paintEvent() behaviour

    I have a problem with some crash of a widget as I do nothing with it! So since it was curious that a widget could crash as it should be inactive, I started to put printf() lines everywhere to determine WHERE it crashed. And my first surprise was to discover that paintEvent() is called many times, actually it is called at regular time steps, even if I do not touch any part of my computer! So why this strange behaviour?
    Second it appears that the crash occurs when the indexAt() function of my QAbstractItemView() inherited class returns an invalid QModelIndex(). I suspected that an obvious and valid reimplementation of indexAt() was return QModelIndex(); What is wrong here?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget::paintEvent() behaviour

    Could you paste the backtrace by the time of a crash and possibly relevant parts of the QAbstractItemView subclass code?
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWidget::paintEvent() behaviour

    Quote Originally Posted by jpn View Post
    Could you paste the backtrace by the time of a crash and possibly relevant parts of the QAbstractItemView subclass code?
    Yes so I have simplified the code at the maximum rate, which yields now:
    Qt Code:
    1. void
    2. myClass::paintEvent(QPaintEvent *event)
    3. {
    4. printf("paint in\n");
    5. setDirtyRegion(this->viewport()->rect());
    6. QAbstractItemView::paintEvent(event);
    7. printf("paint out\n");
    8. return;
    9. }
    10. myClass::indexAt(const QPoint &point) const
    11. {
    12. printf("index in\n");
    13. return QModelIndex();
    14. }
    To copy to clipboard, switch view to plain text mode 
    and the resulting output (I have deleted dozen of "paint in - paint out" sequences for clarity reasons:
    Qt Code:
    1. paint in
    2. paint out
    3. paint in
    4. paint out
    5. paint in
    6. paint out
    7. paint in
    8. paint out
    9. paint in
    10. paint out
    11. paint in
    12. paint out
    13. index in
    14. ASSERT failure in QList<T>::operator[]: "index out of range", file /Library/Frameworks/QtCore.framework/Headers/qlist.h, line 390
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWidget::paintEvent() behaviour

    You shouldn't call QAbstractItemView::setDirtyRegion() inside paintEvent() because it schedules an update so you've got an infinite loop there. And QAbstractItemView::paintEvent() doesn't paint anything for you...

    About the indexAt() crash, could you run the application via debugger and get a backtrace so that we know where the call comes from, please?

    PS. What kind of view are you going to implement? Is it really something which cannot be achieved by customizing already existing views?
    J-P Nurmi

  5. #5
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWidget::paintEvent() behaviour

    Quote Originally Posted by jpn View Post
    You shouldn't call QAbstractItemView::setDirtyRegion() inside paintEvent() because it schedules an update so you've got an infinite loop there. And QAbstractItemView:aintEvent() doesn't paint anything for you...

    About the indexAt() crash, could you run the application via debugger and get a backtrace so that we know where the call comes from, please?

    PS. What kind of view are you going to implement? Is it really something which cannot be achieved by customizing already existing views?
    Ok I have deleted both undesirable calls above, which of course did not change the situation regarding the crash.
    As for the crash, I tested my application on Ubuntu and...it does not crash! So probably an issue with my Mac Leopard version (I have Qt 4.3). So for the debugger trace which gdb command do you expect me to run and send you the trace? (I am not familiar with gdb). As I launch gdb I get the following output, which seems to exhibit somme problem in reading symbol information for Qt, may be due to the fact I did not build Qt with debugger options?

    GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct 2 04:07:49 UTC 2007)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin"...
    warning: Unable to read symbols for "QtGui.framework/Versions/4/QtGui" (file not found).

    warning: Unable to read symbols for "QtCore.framework/Versions/4/QtCore" (file not found).
    Reading symbols for shared libraries ........ done

  6. #6
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWidget::paintEvent() behaviour

    Some more information:
    - the crash occurs when moving the mouse over the window, which inherits from QAbstractItemView (mouseMoveEvent() has not been overloaded)
    - there is no probem with Qt 4.2.3 on Ubuntu
    - the problem occurs with Qt 4.3.2 on Mac OsX Leopard and Qt 4.3.4 on Linux (don't know the family, colleague's PC)
    So could it be a problem from version 4.3 ?

Similar Threads

  1. Disable default tab behaviour for a QGraphicsItem
    By nmather in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2017, 11:30
  2. QAbstractItemView selection behaviour issue
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 17:33
  3. Different behaviour on different distributions
    By Kumula in forum Qt Programming
    Replies: 17
    Last Post: 7th March 2006, 00:58
  4. Replies: 1
    Last Post: 26th February 2006, 06:52
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 07:17

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.