Text from database to QStandardItemModel
-
look this:
Qt5.6.0
void QStandardItemModel::setItem(int row, int column, QStandardItem *item);
maybe you can use it like this:
setItem(row,0,&NameD); -
Hi
Its not really clear what you are trying but if you are trying to ADD
new items, you should new EACH of them.QStandardItemModel model(4, 4); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { // Create new Item QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); // add it model.setItem(row, column, item); } }
Also if from database, why not just take it directly using QSqlQueryModel:
QSqlQueryModel* model = new QSqlQueryModel();
model->setQuery("select firstname from person"); // display all firstnames -
Hi
Its not really clear what you are trying but if you are trying to ADD
new items, you should new EACH of them.QStandardItemModel model(4, 4); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { // Create new Item QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); // add it model.setItem(row, column, item); } }
Also if from database, why not just take it directly using QSqlQueryModel:
QSqlQueryModel* model = new QSqlQueryModel();
model->setQuery("select firstname from person"); // display all firstnamesHi @mrjj,
I tried the second solution first. When I usedQSqlTableModel *model = new QSqlTableModel(); model->setQuery ("SELECT Name FROM Item" );
I got the following error message:
C:\Programming\Projects\Folkfriends\mainwindow.cpp:42: error: no matching function for call to 'QSqlTableModel::setQuery(const char [22])'
model->setQuery ("SELECT Name FROM Item" );What did I miss?
-
@gabor53
ok. no idea then.
http://doc.qt.io/qt-5/qsqlquerymodel.htmlWhat version of Qt do you have ? did you compile yourself?
-
@gabor53
ok. no idea then.
http://doc.qt.io/qt-5/qsqlquerymodel.htmlWhat version of Qt do you have ? did you compile yourself?
-
Hi,
That's because you are using a QSqlTableModel, you should use a QSqlQueryModel.
QSqlTableModel goal is to make a table accessible.
-
Hi,
That's because you are using a QSqlTableModel, you should use a QSqlQueryModel.
QSqlTableModel goal is to make a table accessible.
QSqlTableModel
Good catch :)