void Dialog::createModel()
{
// qstr << "hello"<<"world"<<"this"<<"is"<<"cool"<<"qt";
qstr.append("hello");
qstr.append("world");
qstr.append("this");
qstr.append("is");
qstr.append("cool");
qstr.append("qt");
booksModel->insertRows(0,2);
booksModel->insertColumns(0,3);
int k=0;
for(int i=0;i<booksModel->rowCount();i++)
{
for(int j=0;j<booksModel->columnCount();j++)
{
// QStandardItem *item = new QStandardItem(QString::number(j));
//booksModel->setData(index,QVariant((i+1)*(j+1)));
booksModel
->setData
(index,
QVariant(qstr
[k
]));
k++;
}
}
}
void Dialog::createModel()
{
QStringList qstr;
// qstr << "hello"<<"world"<<"this"<<"is"<<"cool"<<"qt";
qstr.append("hello");
qstr.append("world");
qstr.append("this");
qstr.append("is");
qstr.append("cool");
qstr.append("qt");
booksModel = new QStandardItemModel();
booksModel->insertRows(0,2);
booksModel->insertColumns(0,3);
int k=0;
for(int i=0;i<booksModel->rowCount();i++)
{
for(int j=0;j<booksModel->columnCount();j++)
{
// QStandardItem *item = new QStandardItem(QString::number(j));
QModelIndex index = booksModel->index(i,j,QModelIndex());
//booksModel->setData(index,QVariant((i+1)*(j+1)));
booksModel->setData(index,QVariant(qstr[k]));
k++;
}
}
}
To copy to clipboard, switch view to plain text mode
Question 1) Is there any way that I can pass "qstr" instead of "qstr[k]" and still it prints out everything correctly in tableview? I mean a structure that can be passed directly to set data such that I don't have to use for loop?
Question 2) Instead of append can I populate qstr using "qstr << "hello"<<"world"<<"this"<<"is"<<"cool"<<"qt";"
Question 3) How to use foreach loop instead of for loop in above case?
Bookmarks