I am working on an application which has a view which generates a report to display to the user. This report is something which I’m needing to filter. Using the SQL support in Qt I’ve tried using QSqlTableModel with its filtering capabilities, but it doesn’t seem to find the view as I get the error “Unable to find table TABLE_NAME”. How does one model a view in Qt? I’ve not been able to find any information specifically on that.
QSqlDatabase connection(Request_Connection("DB Name"));
QSqlTableModel* pStore(new QSqlTableModel(NULL, connection));
if (connect(connection))
pStore->setTable("ViewName");
If u have an error “Unable to find table TABLE_NAME” it just means that you are trying to get data from non existing table. Check your database.
EDIT
Okay, that’s weird what u have done. It should more looks like this:
That’s for open database. In first quotes you have a name of sql which you use. Here you can found all available sql plugins. When you connect to database, you can read some data. If you want to use QSqlTableModel for this, you can do it this way:
This simple example will load ‘Name’ and ‘Salary’ columns from ’employee’ table and will display it in ‘view’ QTableView. That’s how you should do it.