PDA

View Full Version : Realtime TableView filter with (lineEdit)



xgoan
21st December 2006, 14:52
Hi,

I want to know how to do a hide/show filter on a QTableView. In the same way as the KDE applications.

I've tried this code but it's too slow:


void MainWindow::on_lineEdit_textChanged(const QString &text){
FilterThread thread(text, queryModel, tableView);

thread.run();
}
FilterThread::FilterThread(QString text, QueryModel *model, QTableView *table, QObject *parent):QThread(parent){
m_text=text;
m_model=model;
m_table=table;
}
void FilterThread::run(){
for(int i=0;i<m_model->rowCount();i++){
QString title=m_model->data(m_model->index(i, 3)).toString();

m_table->setRowHidden(i, title.indexOf(m_text, 0, Qt::CaseInsensitive)==-1);
}
}
Thank's

jpn
21st December 2006, 15:07
Don't modify widgets from any other thread than the main GUI thread: (http://doc.trolltech.com/4.2/threads.html#qobject-reentrancy)


Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.


Try QSortFilterProxyModel, or if that's a QSqlQueryModel, maybe you could do the filtering on the database side?

xgoan
21st December 2006, 15:17
Don't modify widgets from any other thread than the main GUI thread: (http://doc.trolltech.com/4.2/threads.html#qobject-reentrancy)


Try QSortFilterProxyModel (http://doc.trolltech.com/4.2/qsortfilterproxymodel), or if that's a QSqlQueryModel, maybe you could do the filtering on the database side?

The Thread was a try to speed up the action.

The problem of try the db side is that I only want to hide the rows, not remove it. And yes it's a QSqlQueryModel derived class. (QODBC MSAccess conection)