Skip to content
Advertisement

Is it posible to find index-row and values with QRegExp with search name?

I want to find the row-index with searching word using with QSortFilterProxyModel and QtCore.QRegExp. I want to create a list with “mobile” and “email” columns only from the row which is finding from the variable of QRegExp. Below is example code:

JavaScript

I want to print the row.index and insert the value of “mobile” and “email” of the row into list_a. How is it possible or is there any other solution for Request?

Advertisement

Answer

It is not necessary to create a model to filter elements based on a regex since the Qt sqlite driver allows to use the regex function enabling it through QSQLITE_ENABLE_REGEXP using setConnectOptions() method:

JavaScript

If you still want to use QSqlTableModel then you can also use the setFilter method:

JavaScript

If you still want to use QSqlTableModel + QSQSortFilterProxyModel then apart from the filter you have to map the position of the rows:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement