PDA

View Full Version : QTableWidget::item to Double?



Afflicted.d2
30th October 2006, 00:39
How do I convert QTableWidget::item to double?


void Method::setMatrix()
{
for (int i = 0; i < rowCount; ++i)
{
for (int j = 0; j < columnCount; ++j)
{
a[i][j] = table->item(i, j);
}
}
}

munna
30th October 2006, 04:20
Like this




QTableWidgetItem *item = table->item(i,j);
a[i][j] = item->text().toDouble();

jpn
30th October 2006, 06:23
You can even set the data to the table widget as doubles instead of text. Then you'd have double spin boxes in editing mode (editors will be line edits if you set the data as text) and you'll avoid explicitly converting the string to a double again and again (instead you'll get directly the double contained by the variant):



// set
double num = ...
QTableWidgetItem* item = ...
item->setData(Qt::DisplayRole, num);

// get
double result = item->data(Qt::DisplayRole).toDouble();