table = new QTableView(); model = new QSqlQueryModel; table->setModel(model);void frmFind::find(QString text) { QString tmp; QRegExp rx("^"+text+""); for (int i=0;i<table->model()->rowCount();i++){ tmp = table->model()->data(table->model()->index(i,0)).toString(); if (rx.exactMatch(tmp)){ table->scrollTo(table->model()->index(i+10,0)); table->setCurrentIndex(table->model()->index(i,0)); return ; } } return ;}
QString text="mytext"; QModelIndexList match; QModelIndex firstMatch; match = table->model()->match(table->model()->index(0,0),Qt::DisplayRole, text); firstMatch=match.value(0); if (firstMatch.isValid()) { return firstMatch; }