QPopupMenu::keyPressEvent broken in 3.1.2

David Faure dfaure at trolltech.com
Fri Mar 14 12:24:05 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

How to reproduce:
With Qt 3.1.2, use the "menu" example, and press Alt+F then P.

QGList::locate: Index 8 out of range
will appear (and since I have an assert there I can't say what happens
then, but I guess it won't activate the Print menuitem as it should).

The diff from Qt-3.1.1 to Qt-3.1.2 reads as follows:

@@ -1924,6 +1938,7 @@ void QPopupMenu::keyPressEvent( QKeyEven
        QMenuItem* firstAfterCurrent = 0;

        register QMenuItem *m;
+       mi = 0;
        int indx = 0;
        int clashCount = 0;
        while ( (m=it.current()) ) {
@@ -1949,6 +1964,8 @@ void QPopupMenu::keyPressEvent( QKeyEven
                    }
                }
            }
+           if ( mi )
+               break;
            indx++;
        }

This is useless, mi isn't set in the loop at all!

@@ -1956,7 +1973,7 @@ void QPopupMenu::keyPressEvent( QKeyEven
            mi = first;
            popup = mi->popup();
            if ( popup ) {
- -               setActiveItem( indexOf( mi->id() ) );
+               setActiveItem( indx );
                hidePopups();
                popupSubMenuLater( 20, this );
                popup->setFirstItemActive();

And therefore indx is always equal to the number of items in the popupmenu,
so setActiveItem( indx ) goes out of bounds.
I think the fix is to simply revert this change, or to introduce a new int,
which is set to indx when "first" is set, inside the loop, to remember which index
it was at.
Ah well, code speaks more than words, see attached patch ;)

- -- 
David FAURE, faure at kde.org, sponsored by TrollTech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
How to write a Makefile.am for KDE/Qt code:
http://developer.kde.org/documentation/other/makefile_am_howto.html


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+ccnl72KcVAmwbhARAgSdAJ9zhYoo0eZNKK5Yp2uELYlLZWYw5ACeIoZ8
62dtCOfp+rf7pJt9VSo3iy4=
=V4eH
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qpopupmenu.cpp.diff
Type: text/x-diff
Size: 1912 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030314/e0e93980/attachment.diff>


More information about the kde-core-devel mailing list