PDA

View Full Version : QWidget::paintEvent() behaviour



Caius Aérobus
30th March 2008, 14:03
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?

jpn
30th March 2008, 16:02
Could you paste the backtrace by the time of a crash and possibly relevant parts of the QAbstractItemView subclass code?

Caius Aérobus
30th March 2008, 17:32
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:

void
myClass::paintEvent(QPaintEvent *event)
{
printf("paint in\n");
setDirtyRegion(this->viewport()->rect());
QAbstractItemView::paintEvent(event);
printf("paint out\n");
return;
}
QModelIndex
myClass::indexAt(const QPoint &point) const
{
printf("index in\n");
return QModelIndex();
}
and the resulting output (I have deleted dozen of "paint in - paint out" sequences for clarity reasons:

paint in
paint out
paint in
paint out
paint in
paint out
paint in
paint out
paint in
paint out
paint in
paint out
index in
ASSERT failure in QList<T>::operator[]: "index out of range", file /Library/Frameworks/QtCore.framework/Headers/qlist.h, line 390

jpn
30th March 2008, 17:39
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?

Caius Aérobus
4th April 2008, 11:03
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?

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

Caius Aérobus
11th April 2008, 17:55
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 ?