terrible bug (feature?) in KdialogBase

Ravikiran Rajagopal ravi at ee.eng.ohio-state.edu
Tue Apr 1 21:33:48 BST 2003


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

Hello,

> Ugh, that's nasty. Does the attached patch help?

It does for me. However, the code in the example makes an assumption that is 
not generally valid. See below.

> > Thus, all programs of this kind will crash:
> >
> > 	QList<someType> myList;
> > 	myList.append(someObj);
> > 	myList.append(someObj);
> > 	myList.append(someObj);
> > 	myList.append(someObj);
> > 	myList.append(someObj);
> >
> > 	   ...
> > 	myList.at(activePageIndex());

This is really bad however. The implicit assumption is that KJanusWidget will 
start assigning indices from 0 continuously. It would be safer (and also 
better programming practice) to use something like the following:

   QMap<int,someType> myList;
   myPage = addPage(...);
   myList[pageIndex(myPage)] = someObj;
   [...]
   someType wantedObject = myList[activePageIndex()];

This way, we don't run into random crashes. Note that the implicit assumption 
mentioned above is no longer valid if a page is deleted (which is a feature 
of KJanusWidget, and hence, of KDialogBase). In such cases, the method 
outlined above is the right way.

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

iD8DBQE+ife0bI8Y8y0oVXcRAvOTAJ9x8riS5eG7I5QddnzsdXHCVFnOQACfVoX9
teSszlWmHDTRG+tTYv79ghU=
=c+Yl
-----END PGP SIGNATURE-----

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<




More information about the kde-core-devel mailing list