hi,
how can i read QTableWidget cells contents?
regards
n
hi,
how can i read QTableWidget cells contents?
regards
n
Dont you have QTableWidgetItem ?
QTableWidget::item
yes
if it is possible, please provide a simple code
See class documentation for QTableWidgetItem.
What data exactly you mean ? and how do you fill the QTableWidget ?
both text and double data
I've got solution - I did it today and it may help you (QT Creator 1.3.1 + Qt 4.6.2):
It's terrible thing - I needed about 2 hours :/
My example shows reading from cell with coordinates: (0,0):
Qt Code:
To copy to clipboard, switch view to plain text mode
Last edited by Rewo; 3rd April 2010 at 21:32.
Be carefull with the above code, your using a pointer without alocating memory, instead do:
Qt Code:
To copy to clipboard, switch view to plain text mode
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
john_god, how your example differs from Rewo's example, those seems to be same?
The issue where you should be careful is that if the cell does not have item the item()-method returns NULL which means that you should check the validity of the pointer before accessing cell's content. That said this is implementation issue, if you implement your table in a way that there is always item in every cell then this kind of check is not needed. Next is a common pattern in my own table related handling methods:
Qt Code:
if (itab) { : : }To copy to clipboard, switch view to plain text mode
in the end, it's the same, but I'm simplifying code by eliminating itab an reading directly from item.
I agree with wath you said about cell validation, to me its all correct.
Just a side note, for writing cell content I usually do a pattern like this:
Qt Code:
if (tableWidget->item(i,j) == 0) { tableWidget->setItem(i,j, newItem); } else { tableWidgetMatrix->item(i, j)->setText("some text"); }To copy to clipboard, switch view to plain text mode
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Bookmarks