Hi,
I have const QModelIndex &index and I can read the data by example:
Code:
index.model()->data(index, Qt::DisplayRole).toString()
but how can I read the data from column = 0 (or any other column) and row = index.row() from this same model?
Printable View
Hi,
I have const QModelIndex &index and I can read the data by example:
Code:
index.model()->data(index, Qt::DisplayRole).toString()
but how can I read the data from column = 0 (or any other column) and row = index.row() from this same model?
Code:
model->data(model->index(row, col), Qt::DisplayRole);
Tanks, but I get:
in line:Quote:
error: invalid conversion from `const QAbstractItemModel*' to `QAbstractItemModel*'
:/
Try:
Code:
model->data(model->index(row, col), Qt::DisplayRole);
Would you kindly add more of your code, I have a similar questions and I found this post, I'm having problem accessing the right data.
in my main constructor, I have the following connect statement:
Then, using an example I found online ... my slot is defined below, but I get error with the view widget 'viewAppPatients' (which is a QTableView)Code:
connect( viewAllPatients, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(rowDoubleClicked(QModelIndex)));
Code:
{ if (value.isValid()) sRec = value.toString(); qDebug() << sRec; }
So, these posts make wonder where would I define/use AbstracItemModel, because this is how I defined model in my constructor:
Code:
model->setQuery("SELECT FirstName,LastName FROM Clients"); model->setHeaderData(0,Qt::Horizontal, tr("First")); model->setHeaderData(1,Qt::Horizontal, tr("Last Name")); viewAllPatients->setModel(model); viewAllPatients->setAlternatingRowColors(true);
typo, I meant:
I get error with the view widget 'viewAllPatients' (which is a QTableView)
Update: I fixed the issue and found why I was getting errors.
In my header file under private, I defined the QTableView:
So my Slot callback reads:
And now, I don't have the error message:Code:
{ if (value.isValid()) sRec = value.toString(); qDebug() << sRec; }
Code:
error: ‘viewAllPatients’ was not declared in this scope