Hi guys, im rather new to Qt and im following a book : Foudations of Qt Development. Im trying to use the QTableView to display data, but it doesnt seem to work, it only displays a empty viewer.
This is my constructor:
MainDialog
::MainDialog(QWidget *parent
) : QDialog(parent
), ui
(new Ui
::MainDialog) {
// ui->setupUi(this);
for (int row = 0; row < 5; ++row){
for (int col = 0; col < 2; ++col){
if (col == 0){
for (int i = 0; i < 3; ++i){
}
}
model.setItem(row, col, item);
}
}
table->setModel(&model);
table->show();
layout->addWidget(table);
setLayout(layout);
}
MainDialog::MainDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::MainDialog)
{
// ui->setupUi(this);
QTableView *table = new QTableView;
QStandardItemModel model(5, 2);
for (int row = 0; row < 5; ++row){
for (int col = 0; col < 2; ++col){
QStandardItem *item = new QStandardItem(QString("Row:%1, Column:%2").arg(row).arg(col));
if (col == 0){
for (int i = 0; i < 3; ++i){
item->appendRow(new QStandardItem( QString("Item %1").arg(i)));
}
}
model.setItem(row, col, item);
}
}
table->setModel(&model);
table->show();
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(table);
setLayout(layout);
}
To copy to clipboard, switch view to plain text mode
Please be forgiving with your words as im really new thanks
Bookmarks