Results 1 to 6 of 6

Thread: Slow refresh QTableView with sort

  1. #1
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Slow refresh QTableView with sort

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slow refresh QTableView with sort

    Why do you set the model again?
    You don't seem to use different models.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Slow performance QTableView (setQuery, setModel)

    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.
    Last edited by Mhaylson; 21st August 2015 at 16:17.

  4. #4
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: Slow refresh QTableView with sort

    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?
    Last edited by Mhaylson; 21st August 2015 at 22:11.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slow refresh QTableView with sort

    Quote Originally Posted by Mhaylson View Post
    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?

    Quote Originally Posted by Mhaylson View Post
    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,
    _

  6. #6
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow refresh QTableView with sort

    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?

Similar Threads

  1. Slow refresh QsqlQueryModel with QTableView
    By Mhaylson in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2015, 17:27
  2. Replies: 18
    Last Post: 18th January 2013, 12:21
  3. [model/view] slow refresh on big table
    By lauranger in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2008, 21:40
  4. QTableView Repaint/Refresh
    By millsks in forum Newbie
    Replies: 9
    Last Post: 10th January 2008, 17:18
  5. QTableView refresh
    By eleanor in forum Qt Programming
    Replies: 9
    Last Post: 6th October 2007, 18:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.