Problem with new QTableWidgetItem
An error occurs when running this:
My h:
My cpp:
Code:
conTable = 0;
var1 = 0;
ui->tableWidget->setItem(var1,0,itemTable[conTable]);
conTable++;
ui->tableWidget->setItem(var1,1,itemTable[conTable]);
conTable++;
What's wrong in making a new in QTableWidgetItem?
Re: Problem with new QTableWidgetItem
Normal, your
Quote:
QTableWidgetItem* itemTable[];
is something equivalent to QTableWidgetItem **itemTable.
But you do the allocation of QTableWidgetItem but not it's address.
Seriously this is C code, use Qt containers instead, look to QVector or QList. Something like
Quote:
QVector<QTableWidgetItem *> itemTable;
should be fine.
Re: Problem with new QTableWidgetItem
I don't understand.
I use the normal QTreeWidgetItem and it works.
Code:
itemTree[num]->setText(0,Tag[num]->nome);
num++;
Use vector will be a problem.
I want use as a pointer and create indefinitely to fill a table.
Re: Problem with new QTableWidgetItem
you may have to format it more like this so that you can access the item later.
Code:
ui.
table->item
(row ,
0 )->setText
(QString( "%1" ).
arg( num
) );
ui.
table->item
(row,
0 )->setBackgroundColor
( QColor(178,
34,
34) );
Something I found out after hours of invalid pointer access
Re: Problem with new QTableWidgetItem
Perfect.
That's what I needed.
Thanks.
Re: Problem with new QTableWidgetItem
Where do you allocate space to hold the array of QTableWidgetItem pointers? If you never do that then this a recipe for serious crashing. Using a QList<QTableWidgetItem*> or QVector<QTableWidgetItem*> is a far safer option.
Re: Problem with new QTableWidgetItem
Chris was that to me?
They get held into the QTableWidget, I just reference them in the row and col of the table ( item( row, col) ), for my application they work fine, no issues, and no risk. They only get replaced when i say so.
Re: Problem with new QTableWidgetItem