PDA

View Full Version : Documentation problem.



impeteperry
4th October 2006, 23:37
I am fairly new to Qt and I am having problem in decoding some of the documentation, particularly in Qt4.
Example:. I have a QTableWidget, "myTable", and I want to myTable->set Item(3, 4, "somthing");
What should the code look like?

The Doc. has "void QTableWidget::setItem ( int row, int column, QTableWidgetItem * item )". Fine, but....

I go to QTableWidgetItem and am totally lost.

Thanks.

jacek
5th October 2006, 00:40
I have a QTableWidget, "myTable", and I want to myTable->set Item(3, 4, "somthing");
What should the code look like?
It should be:

myTable->setItem( 3, 4, new QTableWidgetItem( "somthing" ) );

QTableWidgetItem represents the cell in the table.

impeteperry
5th October 2006, 02:45
Thanks for the prompt, helpful reply. I found about the samething in chapt03 of "programming in Qt4".

I haven't gotten the logic behind the "new" yet since I have designated the "cell", but I shall. Thanks.

jacek
5th October 2006, 03:12
I haven't gotten the logic behind the "new" yet since I have designated the "cell", but I shall.
new is an operator that creates class instance on the heap and returns a pointer to it.


myTable->setItem( 3, 4, new QTableWidgetItem( "somthing" ) );
is equivalent of:

QTableWidgetItem *item = new QTableWidgetItem( "somthing" );
myTable->setItem( 3, 4, item );

It the item already exists, you can access it like this:
myWidget->item( 3, 4 )->setText( "something" );

impeteperry
5th October 2006, 20:42
Ok I think I understand. Each cell is, in effect, a child of the table rather than a part of the table itself and thus must be dclared separately. Am I right?

Thanks.

jacek
5th October 2006, 21:30
Each cell is, in effect, a child of the table rather than a part of the table itself and thus must be dclared separately. Am I right?
Yes, each cell is represented by a distinct object and QTableWidget acts like a container for them.

impeteperry
6th October 2006, 02:06
Thanks.

Good Night.