PDA

View Full Version : QTableWidget click in empty space results in error?



Giel Peters
19th January 2006, 22:17
Hi all,

I need a hint!

I've connected a signal like this:
connect(personeelTableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(clickOntvangen(int, int)));

to a QTableWidget ( personeelTableWidget ) the table widget has 4 filled rows and a lot of open space. When I click in the empty space nothing happens (that is de slot "clickOntvangen" is not called. I think thats correct!.
When I click one off the cells in the table widget the slot "clickOntvangen" gets called, just as expected!. But when I click in the empty space, after a valid selection of a cell, the application terminates with the following message:


ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/local/Trolltech/Qt-4.1.0/include/QtCore/qlist.h line 369

Can somebody give me a hint how to avoid this kind of behavior because I don't like it?

regards,

Giel
P.S. in the preview there's a smilie on the wrong place, could not delete it! ( it is not in the original message :)

yop
19th January 2006, 22:55
ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/local/Trolltech/Qt-4.1.0/include/QtCore/qlist.h line 369
I don't think that the problem is in your connection, could you please elaborete more on your code?

P.S. in the preview there's a smilie on the wrong place, could not delete it! ( it is not in the original message :)
Use the [C O D E] tags to avoid it, see below

AClass::privateMember(funnyLooking);

AClass::privateMember(notFunnyLooking);

jacek
20th January 2006, 00:33
Use the [C O D E] tags to avoid it
You can also select "Disable smilies in text" from "Additional Options" section below the editor.

Giel Peters
20th January 2006, 22:34
Yop,

that was the hint I needed!

there was one more connection i made in my connection routine:
void Personeel::connectSignals()
{
connect(personeelTableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(clickOntvangen(int, int)));
connect(personeelTableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(selectieOntvangen()));
}

The second connection was made to the following slot:

void Personeel::selectieOntvangen( )
{
QList<QTableWidgetSelectionRange> dezeSelectie;// = new QTableWidgetSelectionRange();
dezeSelectie = personeelTableWidget->selectedRanges();
if( dezeSelectie[0].rowCount() == 1 && dezeSelectie[0].columnCount() == personeelTableWidget->columnCount() )
{
personeelTableWidget->insertRow( 1 );
}
}

This routine called the ASSERT.

I changed it to this:

void Personeel::selectieOntvangen( )
{
QList<QTableWidgetSelectionRange> dezeSelectie;// = new QTableWidgetSelectionRange();
dezeSelectie = personeelTableWidget->selectedRanges();
if(dezeSelectie.count() != 0)
{
if( dezeSelectie[0].rowCount() == 1 && dezeSelectie[0].columnCount() == personeelTableWidget->columnCount() )
{
personeelTableWidget->insertRow( 1 );
}
}
}

and the problem was solved!
When clicked in empty space when there is a selection made of one or more cells the QList holds nothing, I did not test for "nothing" in my early routine

In dutch: "I did not look further then my nose was long!"

thanks for the hint,

regards,
Giel Peters

yop
21st January 2006, 01:07
Wow my eyes hurt when I read your code :eek: Is it Dutch? Maybe I should put some greek in your code with latin characters (we call them greeglish) to see who hurts the other the most :p .
Anyway besides fun, I didn't do much I just pointed you away from the wrong direction. I'm glad it was enough :)