PDA

View Full Version : Qt4 - QSqlQueryModel x Qt3 QDataTable



ederbs
8th September 2007, 20:48
Hello Friends,

I am porting my application that was in Qt3 for Qt4.

Good, it would like to take off a doubt, I I used the QDataTable in the Qt3, now
I am using the QTableView with the QSqlQueryModel.

I had the following code before.

=Qt3 part code===========================
...
QString sql = QString("SQL OF 130 LINES").arg(idGlobal);

QSqlSelectCursor *cur = new QSqlSelectCursor(sql);

dataTable->addColumn("id_1", tr("Nº"), 70);
dataTable->addColumn("id_2", tr("Test"), 30);
...
=Qt3 end code============================

Now in the Qt4 I am making thus:

=Qt4 part code===========================
...
QSqlQueryModel *model = new QSqlQueryModel(this->tableView);
model->setQuery(QString("O SQL GRANDE").arg( globalIdentID ));

model->setHeaderData(0, Qt::Horizontal, QObject::tr("Nº"))
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Nº"))
...
=Qt4 end code============================

This functions, more the doubt is, as I make to only bring fields that I desire, eat I I made before when I added the column in the QDataTable. Therefore this SQL returns a mount from thing, more I wants only determined fields, thus making it brings everything in the screen.

Somebody knows as can make this?

edm.

wysota
9th September 2007, 00:35
I'm not sure what you mean, but if you want to have only some of the columns of the model visible, you can either hide respective columns in the table view (which is a worse possibility) or apply a filter model on the original model that will filter out unwanted columns. Or you can change the SQL query so that it only contains the columns you want, but I guess you are aware of that.

ederbs
9th September 2007, 19:49
Hi,

I did not understand, As I can create this filter? Unhappyly consultation SQL cannot be modified.

edm

wysota
10th September 2007, 08:38
Take a look at QSortFilterProxyModel class.