GreyGeek
5th December 2006, 21:30
Folks,
I am trying to create a method that can take a user's input and scan a QTableView object for a matching value in column 1. So far, my code is:
void supervisormaint::searchNames(){
QString findName = sui.leSearchText->text().trimmed();
QAbstractItemModel *modl = sui.EmployeesView->model();
QModelIndex curr = sui.EmployeesView->currentIndex();
int rc = modl->rowCount(curr.parent());
QString name;
QVariant vname;
QModelIndex rIndex;
for(int row = 0; row < rc; row++){
rIndex = modl->createIndex (row, 1, 0);
vname = modl->data(rIndex, 0);
name = vname.toString();
if (name.length() > 0 && name.contains(findName) == 0){
sui.EmployeesView->scrollTo(rIndex);
return;
}
}
QMessageBox::information(this,"Name Search:", findName + " NOT found!");
}
but my stumbling block is
rIndex = modl->createIndex (row, 1, 0);
which returns the compiler error:
'QAbstractItemModel::createIndex' : cannot access protected member declared in class 'QAbstractItemModel'
It appears that modl allows only for a single item index selected by the user.
I couldn't find a method to create an index array which would contain all 451 indexes that the view contains.
How do I do it?
:confused:
I am trying to create a method that can take a user's input and scan a QTableView object for a matching value in column 1. So far, my code is:
void supervisormaint::searchNames(){
QString findName = sui.leSearchText->text().trimmed();
QAbstractItemModel *modl = sui.EmployeesView->model();
QModelIndex curr = sui.EmployeesView->currentIndex();
int rc = modl->rowCount(curr.parent());
QString name;
QVariant vname;
QModelIndex rIndex;
for(int row = 0; row < rc; row++){
rIndex = modl->createIndex (row, 1, 0);
vname = modl->data(rIndex, 0);
name = vname.toString();
if (name.length() > 0 && name.contains(findName) == 0){
sui.EmployeesView->scrollTo(rIndex);
return;
}
}
QMessageBox::information(this,"Name Search:", findName + " NOT found!");
}
but my stumbling block is
rIndex = modl->createIndex (row, 1, 0);
which returns the compiler error:
'QAbstractItemModel::createIndex' : cannot access protected member declared in class 'QAbstractItemModel'
It appears that modl allows only for a single item index selected by the user.
I couldn't find a method to create an index array which would contain all 451 indexes that the view contains.
How do I do it?
:confused: