How do I convert QTableWidget::item to double?
Qt Code:
void Method::setMatrix() { for (int i = 0; i < rowCount; ++i) { for (int j = 0; j < columnCount; ++j) { a[i][j] = table->item(i, j); } } }To copy to clipboard, switch view to plain text mode
How do I convert QTableWidget::item to double?
Qt Code:
void Method::setMatrix() { for (int i = 0; i < rowCount; ++i) { for (int j = 0; j < columnCount; ++j) { a[i][j] = table->item(i, j); } } }To copy to clipboard, switch view to plain text mode
Last edited by wysota; 30th October 2006 at 07:48. Reason: missing [code] tags
Like this
Qt Code:
a[i][j] = item->text().toDouble();To copy to clipboard, switch view to plain text mode
Mithin
www.mithin.in
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):
Qt Code:
// set double num = ... item->setData(Qt::DisplayRole, num); // get double result = item->data(Qt::DisplayRole).toDouble();To copy to clipboard, switch view to plain text mode
J-P Nurmi
Bookmarks