Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:20:08+00:00 2026-05-26T04:20:08+00:00

I am trying out the basic QSortFilterProxyModel example in qt assistant and have made

  • 0

I am trying out the basic QSortFilterProxyModel example in qt assistant and have made a QSqlTableModel to try and filter.The example i have made is not filtering as it is should and i need assistance to know why.

/*
ned.h
*/
#ifndef NED_H
#define NED_H

#include <QWidget>
#include <QtSql>
#include "ui_ned.h"

class QSortFilterProxyModel;

class ned : public QWidget
{
    Q_OBJECT

public:
    ned(QWidget *parent = 0);

private:
    void setupModel();
    QSortFilterProxyModel *proxyModel;
    QSqlTableModel *tableModel;
    Ui::ned ui;

private slots:
    void filterRegExpChanged();
};

#endif // NED_H
.................................................................
.................................................................
/*
ned.cpp
*/

#include <QtGui>
#include <QtSql>
#include <QwwClearLineEdit>
#include "ned.h"

ned::ned(QWidget *parent) :
    QWidget(parent)
{
    ui.setupUi(this);
    setupModel();

    tableModel = new QSqlTableModel(ui.tableView);
    tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    tableModel->setTable("tables");

    ui.tableView->setModel(tableModel);

    ui.tableView->setColumnHidden(tableModel->fieldIndex("id"), true);

    ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui.tableView->setAlternatingRowColors(true);
    ui.tableView->setSortingEnabled(true);

    ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui.tableView->horizontalHeader()->setStretchLastSection(true);

    proxyModel = new QSortFilterProxyModel;
    proxyModel->setDynamicSortFilter(true);
    proxyModel->setSourceModel(tableModel);
    proxyModel->setFilterKeyColumn(1);

    tableModel->select();
    //Locale
    tableModel->setHeaderData(1, Qt::Horizontal, tr("Table Name"));
    tableModel->setHeaderData(2, Qt::Horizontal, tr("Table Description"));


    connect(ui.nedsort, SIGNAL(textChanged(QString)),
            this, SLOT(filterRegExpChanged()),Qt::UniqueConnection);

}

void ned::setupModel()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("smith.DAT");
    if (!db.open())
    {
        QMessageBox::critical(0, tr("Cannot open database"),
                              tr("Unable to establish a database connection.\n"
                                 "This example needs SQLite support. Please read "
                                 "the Qt SQL driver documentation for information how "
                                 "to build it."), QMessageBox::Cancel);
        return;
    }
}


void ned::filterRegExpChanged()
{
    QRegExp regExp(ui.nedsort->text());
    proxyModel->setFilterRegExp(regExp);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:20:09+00:00Added an answer on May 26, 2026 at 4:20 am

    This line is wrong:

     ui.tableView->setModel(tableModel);
    

    You have to set the model to the proymodel (later):

     ui.tableView->setModel(proxyModel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying out some basic exercises involving loops. Can someone tell me
I'm trying to figure out how to work git filter-branch and I need help
I am trying out basic submodule functionality in Git Extensions. I have a repository
I'm basically trying to figure out the simplest way to perform your basic insert
Know this might be rather basic, but I been trying to figure out how
Trying out the examples found on pleac.sf.net , I'm not able to get an
Rather new to REST and Jersey, and I'm trying out some basic examples. I've
i was trying out quartz 2d today and i got to learn basic drawing
I'm trying to work out why memory usage in a basic application I'm writing
i feel my beard growing while trying to find out the Problem here. Basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.