View Full Version : QTreeWidget, double-clicks and assertion errors

13th September 2006, 15:06
Qt 4.1.4 commercial version on Windows XP

I've attached a sample program that illustrates what is occurring.

I have two QTreeWidgets and two push buttons (add and remove). The list on the left is the 'available' list. The list on the right is the 'selected' list. As long as I use the Add/Remove buttons everything is fine. When I double-click on an item in the 'selected' list, it will be removed without incident as long as I am not removing the last remaining item. If I attempt to double-click on the last item I get:

ASSERT failure in QVector<T>::at "index out of range"

13th September 2006, 15:29
This error is present in Linux 4.1 too. As a workaround, I am using a timer with 0 timeout, which is triggered after slot handlers return. In the timeout slot I simply delete the item.

void Dialog::on_allTree_userDoubleClicked( const QString &user, int level,
hackitemtodelete = user; // class member storing the item to delete
QTimer::singleShot(0, this, SLOT(hackdeleteitem())); // single shot timer that triggers the delete

void Dialog::hackdeleteitem( ) {
allTree->removeUser(hackitemtodelete); // item gets deleted
hackitemtodelete = ""; // "pointer" is cleared