PDA

View Full Version : Slow refresh QTableView with sort



Mhaylson
21st August 2015, 01:29
I am brazilian, therefore my english is not very good.
Why it slows down my model when I use sort on model andn then have to again update the model?

void ProductSmartSearch::LoadTableView()
{
QString strTemp;

QElapsedTimer timer;
timer.start();

if( !m_isPopDrugStore )
m_ModelProduct->setQuery(SQL_LOCAL_PRODUCTS);
else
m_ModelProduct->setQuery(SQL_LOCAL_PRODUCTS_POP);

m_ui->tableViewSearch->setSortingEnabled(true);
m_ui->tableViewSearch->setModel( m_ModelProduct);
m_ui->tableViewSearch->model()->sort(2,Qt::AscendingOrder);
}

Every time I do a refresh on my table (call the Load function) ... runtime is very time consuming, and is only fast retreat when the method sort. The slowness happens in setModel and setQuery. Please help me!

anda_skoa
21st August 2015, 11:22
Why do you set the model again?
You don't seem to use different models.

Cheers,
_

Mhaylson
21st August 2015, 16:44
I am Brazilian, so my English is not very good. I have a problem when I refresh my QTableView.

I've many records in the table (30,000+ lines) and when sorting data clicking on the header of the table performance are good, but when I make a setQuery (QSqlqueryModel) or a setModel (QTablevieew) again (refresh) the process is rather slow, how can I solve?

The SQL query time: 300 ms and setQuery and setModel time is about 2 seconds for a total of almost 5 seconds. And if I use QSortFilterProxyModel to sort data, how would I do? Help me please, I'm several days trying to solve this.

Mhaylson
21st August 2015, 23:06
Because there was a change in the record.

Other example of code :

m_ModelProduct->setQuery(SQL_LOCAL_PRODUCTS);
proxyModel->setSourceModel(model);
proxyView->setModel(proxyModel);

proxyView->sortByColumn(1, Qt::AscendingOrder);

if I sort the table, it has a long delay to display the table records. If something changes in records I need to make a setQuery again and therefore a setModel, correct?

anda_skoa
22nd August 2015, 11:25
Because there was a change in the record.

That would explain setQuery(), so that the model can load the data again.
But why set the model again? It is the same model, right?



If something changes in records I need to make a setQuery again and therefore a setModel, correct?
Only setQuery(), the pointer to the model stays the same when its data changes.

Anyway, setting the query means the model will reset and get all data from the database again.
Which might be the cause of the performance issue you are seeing.
If you know which records have been altered, you might be able to achieve partial updates by implementing your own model and handling the update yourself.

But better measure which part is the one that consumes most time.
Take the model without it being shown in any view and measure the time it takes for setQuery() to finish.

Cheers,
_

Mhaylson
24th August 2015, 17:36
The problem is that I do not know which record was changed. Let's say the 33 thousand products, some was modified so I need to do further consultation with the heads setQuery, correct?