Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    10

    QSortFilterProxyModel question

    Hello.

    I have the folowing code in one of my dialogs

    Code:
     ui->setupUi(this);
    model = new QSqlTableModel;
    proxyModel = new QSortFilterProxyModel;
    
        proxyModel->setSourceModel(model);
        model->setTable("products");
    
        ui->productsTableView->setModel(proxyModel);
    
        model->select();
    
        connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(setFilterFixedString(QString)));
    Code:
    void ProductsDialog::setFilterFixedString(QString pattern)
    {
        QTime t;
        t.start();
        proxyModel->setFilterFixedString(pattern);
        qDebug() << QString("Searched in %1 miliseconds").arg(t.elapsed());
    }
    it works ok but i have about 50.000 products in my table when filtering it takes a lot of time
    for example when loading 10.000 items in the model the output is "Searched in 52791 miliseconds" which is very slow for what im trying to do (filter the results as the user types). Is something wrong with my code or is the sort-filter proxy slow? Any alternatives to this?

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: QSortFilterProxyModel question

    Did you try with QSqlTableModel::setFilter()?

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    10

    Re: QSortFilterProxyModel question

    Yes i have tried it but that reselects the data and takes about 2 sec to complete (for 10.000). i need to search the model in memory so i do not reselect the data from the database.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QSortFilterProxyModel question

    What are you doing with the data? What sort of filter pattern is being used? What fraction of the table rows are typically returned? Does the result need to be sorted?

    Seems to me that if you're doing a selection, it would be far more efficient to do the query against the table and THEN sort or do whatever other processing is needed, vs extracting and sorting all entries before selecting.

    In a table with 83000 entries, we have a Symbian application that can select and sort a dozen or so entries from the table in sub-second time, using standard Sqlite operations.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    10

    Re: QSortFilterProxyModel question

    I don't need sorting I just need to display the rows that have the search filter in the first colon. Maybe if the database would be an sqlite in memory or a file on my local pc but the server is a remote mysql server and so doing a select that might return thousands of items is not that efficient. Simply I need to hide the rows that do not contain "pattern" in the word of their first colon.

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QSortFilterProxyModel question

    I'll grant you that I don't fully understand QSortProxyModel/QSqlTableModel, but it appears to be extracting ALL the records from the database and selecting from them. At least I don't see anywhere in the description where it says it understands SQL syntax. If you did setFilter on your QSqlTableModel (before doing select) it would be different.

Similar Threads

  1. just question
    By ram4soft in forum Symbian
    Replies: 3
    Last Post: 2007-08-21, 11:20
  2. a question about command and a question about s60
    By t4kesting in forum Mobile Java General
    Replies: 0
    Last Post: 2006-01-24, 09:21
  3. Replies: 1
    Last Post: 2003-04-14, 03:14
  4. some question thanks
    By IGhost in forum Symbian
    Replies: 0
    Last Post: 2002-12-13, 12:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×