PDA

View Full Version : QTableWidgetItem Text



pytro
28th July 2007, 13:51
hi, i am having some issues, by reading values from tableWidget.

GuiApp.h



//..
private:
Ui::GuiAppClass ui;
private slots:
void getTableItemSelected(int,int);


GuiApp.cpp


GuiApp::GuiApp(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
//..
ui.setupUi(this);
connect(ui.tableWidget, SIGNAL(cellClicked(int,int)),
this, SLOT (getTableItemSelected(int,int)));
}

//..
void GuiApp::getTableItemSelected(int row, int col)
{
QTableWidgetItem *locale = ui.tableWidget->item(row, col);
QString text = locale->text();
qDebug("Row %i Col %i Value: %s", row, col, text);
}

The table "prints" the values like 3 23 45. But i read this symbols..
Output:
Row 0 Col 0 Value: ♦
Row 0 Col 1 Value: ♥
Row 0 Col 2 Value: ♦

What's the problem?

Thanks in advance. :)

marcel
28th July 2007, 14:43
The problem is that you are trying to print a directly a QString.
You have to get a reference to it's internal buffer first.



QByteArray ascii = text.toAscii();
qDebug("Row %i Col %i Value: %s", row, col, ascii.constData());


Regards

jpn
6th August 2007, 22:44
One could also include <QtDebug> and use more convenient syntax with built-in support for basic Qt data types, including QString:


#include <QtDebug>
...
qDebug() << locale->text();