I have a piece of code in my application as follows :
....
QStandardItemModel* authorModel = getAuthorModel(author);
// Create result tab
QTableView* tblView = new QTableView();
tblView->setModel(authorModel);
controller.queryAuthor(author, authorModel);
qDebug() << authorModel->setHeaderData(0, Qt::Horizontal, QVariant("Author Name"), Qt::DisplayRole);
qDebug() << authorModel->setHeaderData(1, Qt::Horizontal, QVariant("Author Id"), Qt::DisplayRole);
int tabIdx = ui->mainTabWidget->addTab(tblView, author);
ui->mainTabWidget->setCurrentIndex(tabIdx);
tblView->setColumnHidden(1, true);
This code is called multiple times creating different tableviews. When authorModel is empty, then setting headerdata fails, also, setColumnHidden fails and once the data is populated default numeric headers are shown and column 1 is visible. Both qDebug statements return false.
However, when the same populated model is used to create a new table view, in the new view column 1 is hidden without issues, and headers are set as they should be. Both qDebug statements return true.
What is the problem and how can it be alleviated ?