Hi,
QTableWidgetItem *twi ;
twi= tableWidget->item(row, col) ;
twi->setText(QString) ;
SteveH
Hi,
QTableWidgetItem *twi ;
twi= tableWidget->item(row, col) ;
twi->setText(QString) ;
SteveH
Thanks for reply.
I did that:
Code:
Qt Code:
QTableWidgetItem *itab; itab = tableWidget->item(0,0); itab->setText("X");To copy to clipboard, switch view to plain text mode
Result (during running the program (compilation OK)):
Program works correctly when I delete "itab->setText("X");", but without any result, ofc.
Program works correctly too when I delete "itab = tableWidget->item(0,0);", so this 2 lines collide.
EDIT:
I tried this:
Code:
Qt Code:
QTableWidgetItem *itab; itab->text() = "X"; tableWidget->setItem(0, 0, itab);To copy to clipboard, switch view to plain text mode
And this:
Code:
Qt Code:
QTableWidgetItem *itab; itab->text() = "X"; tableWidget->item(0,0);To copy to clipboard, switch view to plain text mode
But the result is:
EDIT XXX:
It's very very funny, look:
Qt Code:
QTableWidgetItem *itab; itab->text() = "X"; label -> setText(cyce);To copy to clipboard, switch view to plain text mode
OR
Qt Code:
QTableWidgetItem *itab; itab -> setText("X"); label -> setText(cyce);To copy to clipboard, switch view to plain text mode
And the result is of course:
Dunno. It looks like setText and itab->text() = "X"; are wrong here.
Last edited by Rewo; 3rd April 2010 at 22:51.
You have to alocate memory to your pointer
Qt Code:
QTableWidgetItem *itab; itab->setText("X"); tableWidget->setItem(0, 0, itab);To copy to clipboard, switch view to plain text mode
It was crashing because you're setting a value to an unalolocate pointer.
Last edited by john_god; 3rd April 2010 at 23:58.
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
soulless (4th April 2010)
I noticed john_god's post right after I pressed "Submit Reply"
Try this:
Qt Code:
itab->setText("X"); tableWidget->setItem(0, 0, itab);To copy to clipboard, switch view to plain text mode
Last edited by norobro; 4th April 2010 at 01:35. Reason: copied wrong code
Thanks, it helped. But I have one more problem.
I tried to apply that:
Qt Code:
itab -> setText("X"); for(int a=0;a<irows;a++) for(int b=0;b<icols;b++) { tableWidget->setItem(a, b, itab); }To copy to clipboard, switch view to plain text mode
Filling "X" works only for (0,0) cell, while running program, there is statement in compiling console:
"QTableWidget: cannot insert an item that is already owned by another QTableWidget"
If I have 4x3 table, this statement appears 4x3-1=11 times.
I tried to make an "itab" array, but it failed.
I think that itab needs some release from cell, but dunno how to do that.
________
EDIT 2 minutes later:
I did that:
Qt Code:
for(int a=0;a<irows;a++) for(int b=0;b<icols;b++) { itab -> setText("X"); tableWidget->setItem(a, b, itab); }To copy to clipboard, switch view to plain text mode
And it works for me.
Please let me make a sugestion, if you plan to fill the table more than once, use the following code to avoid duplicating items
Qt Code:
for(int a=0;a<irows;a++) for(int b=0;b<icols;b++){ if (tableWidget->itab(a,b) == 0) { itab->setText("X"); tableWidget->setItem(a,b, itab); } else { tableWidget->item(a, b)->setText("X"); } }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