Как получить QModelIndex строки, найденной с помощью SELECT-запроса (QSqlQuery), без изменения исходного QSqlQueryModel
Я уже задавал вопрос, но меня неправильно поняли, поэтому я стараюсь уточнить проблему.
Я использую QSqlQueryModel
для отображения данных из базы данных SQLite, для представления я использую QTableView
,
Теперь я хочу реализовать диалоговое окно "Поиск / Найти / Заменить", чтобы выполнить поиск в базе данных с помощью дополнительно созданного QSqlQuery
и скажем, я нахожу запись.
Итак, как я могу получить из этой найденной записи в моем дополнительном QSqlQuery
к моей модели /view-архитектуре?
The problem is, I want to highlight the found record and therefore I have to load a QItemSelectionModel
с конкретным QModelIndex
,
But I do not know any way how to do this, maybe my plan is not possible and there are other working solutions for finding text in a database model and highlighting the found ones in the QTableView
,
I already know the documentation of QSqlQuery
, QSqlQueryModel
а также QModelIndex
, so please don't refer only to these pages, this wouldn't be much help..
Спасибо!
PS: There is also a related question, which has not been answered yet: "How can i find the QModelIndex for given composite primary key, with QSqlTableModel"
1 ответ
Хорошо, я нашел ответ сам, возможно, у кого-то еще есть такая же проблема, поэтому я выкладываю решение:
Есть функция QAbstractItemModel::match():)