[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#529435: QListBox::current set in insertItem without currentChanged emiting



On Tue, May 19, 2009 at 01:17:24PM +0200, Michal Hocko wrote:
> Package: qt-x11-free
> Severity: normal
> 
> Hi,
> I have just noticed that buggy behavior in my application is caused by
> QListBox::current being set during insertItem without triggering currentChanged.
> My application uses currentChanged handler for enable/disable logic and
> so this doesn't work in case that box was empty.
> 
> I am not sure whether this is correct or not, but it is at least
> inconsistent for cases like:
> 
> box->insertItem(item, pos);
> box->setCurrentItem(pos);
> 
> because this will trigger currentChanged signal only if box wasn't empty
> before.
> 
> I have checked the source and really QListBox::insertItem does something
> like:
> 
>     if ( hasFocus() && !d->current ) {
> 	d->current = d->head;
> 	updateItem( d->current );
> 	emit highlighted( d->current );
> 	emit highlighted( d->current->text() );
> 	emit highlighted( index );
>     }
> 
> I think that we are missing emit currentChanged there.
 
I would suggest the attached patch. Please note that I haven't tested
it. 
There are more places which set current to some value and don't emit
currentChanged but I wasn't sure whether to fix them as well (e.g.
QListBox::mousePressEventEx, QListBox::mouseReleaseEvent).
-- 
Michal Hocko
Index: qt-x11-free-3.3.8b/src/widgets/qlistbox.cpp
===================================================================
--- qt-x11-free-3.3.8b.orig/src/widgets/qlistbox.cpp	2009-05-19 14:01:28.000000000 +0200
+++ qt-x11-free-3.3.8b/src/widgets/qlistbox.cpp	2009-05-19 14:04:47.000000000 +0200
@@ -1482,6 +1482,7 @@ void QListBox::insertItem( const QListBo
     if ( hasFocus() && !d->current ) {
 	d->current = d->head;
 	updateItem( d->current );
+	emit currentChanged( d->current );
 	emit highlighted( d->current );
 	emit highlighted( d->current->text() );
 	emit highlighted( index );
@@ -1538,6 +1539,7 @@ void QListBox::insertItem( const QListBo
     if ( hasFocus() && !d->current ) {
 	d->current = d->head;
 	updateItem( d->current );
+	emit currentChanged( d->current );
 	emit highlighted( d->current );
 	emit highlighted( d->current->text() );
 	emit highlighted( index( d->current ) );

Reply to: