QSqlQueryModel insertColumn() returns false
I am trying to add a new column to a QSqlQueryModel and populate it with data not related to its database. There are 2 columns from the database query. I tried the following code to check if column insertion was successful.
Code:
if(atsFieldModel->insertColumn(2, testIndex.parent()))
QMessageBox::information(this, tr
("Successful"), tr
("column inserted!"));
But the messagebox does not appear. I also used insertColumns() method but it didn't work either. Please explain to me what I did wrong here. Thank you.
Re: QSqlQueryModel insertColumn() returns false
From QSqlQueryModel::insertColumns():
Quote:
The parent parameter must always be an invalid QModelIndex, since the model does not support parent-child relationships.
EDIT: Commented without trying your code. Looks like testIndex.parent() does return an invalid QModelIndex. Try:
Code:
atsFieldModel->insertColumn(2)
Both work for me.
Re: QSqlQueryModel insertColumn() returns false
OMG, it was right there in the documentation, I must have missed it. It worked perfectly. Thanx a lot norobro :)