Hi,
I am very raw with model/view hence the many questions..
On my QSqlTableModel I have the following code to present the data:
{
if (role == Qt::DisplayRole)
{
var = record(index.row()).value("cnty_nam").toString();
qDebug() << index.row() << displayColumnCode << var;
return var;
}
}
QVariant maintModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
QString var;
var = record(index.row()).value("cnty_nam").toString();
qDebug() << index.row() << displayColumnCode << var;
return var;
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
I am just displaying one column thus I just use row. From the debug I can see that the row numbers are fine, also the column exists, but in this case var is always empty! because record(index.row()).value("cnty_nam").isValid() is always false!!!
I initialize the model with:
m_mainmodel = new maintModel(this,db);
m_mainmodel->setTable("country");
if (m_mainmodel->select())
{
ui->ListView1->setModel(m_mainmodel);
}
m_mainmodel = new maintModel(this,db);
m_mainmodel->setTable("country");
m_mainmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (m_mainmodel->select())
{
ui->ListView1->setModel(m_mainmodel);
}
To copy to clipboard, switch view to plain text mode
For sure is something very silly... but I don't know what is happening!!!
Thanks,
Carlos.
Bookmarks