PDA

View Full Version : How to get data from sqlquery that result 3 columns in a row and show only 1 Colum



umen
1st April 2012, 09:17
How to get data from sqlquery that result 3 columns in a row and show only 1 Colum and use the other columns data
hello all
im using QSqlQueryModel subclass to execute sql querys and populate them to tableview
now i have simple sql query that results 3 columns/ fields in a row that invoked in the QSqlQueryModel subclass like this :


QString query_local = "SELECT foo1,foo2,foo3 FROM tbl" ;
QSqlQueryModel::setQuery(query_local, queryDB);

now i what to use the data from foo1 and foo 2 but display only foo3
so in the end there will be only one column in the view per row.

ChrisW67
1st April 2012, 09:48
Do yourself a favour... find an SQL tutorial. If you only want foo3 in the result then only list foo3. Assuming "use the data from foo1 and foo 2" means filtering on those columns then they appear in the WHERE clause.

umen
1st April 2012, 10:14
Hi
sorry but English isn't my native language so i guess i have semantic errors .
what i mean is that i need the data from foo1 and foo2 to use ( store in the Qt::UserRole as string)
but display in the Qt::DisplayRole the result of foo3.
is it more clear ?

Lesiok
1st April 2012, 12:36
RTFM and hint is QTableView::hideColumn (http://qt-project.org/doc/qt-4.8/qtableview.html#hideColumn)

Lykurg
1st April 2012, 13:07
To avoid double answers: http://qt-project.org/forums/viewthread/15861/.
Not so polite to ask the same question in different forums...

EDIT: And here we go: http://qt-project.org/forums/viewthread/15795/.
Menu -> Block User -> add!

umen
2nd April 2012, 08:31
Thanks for the answer , but this dosn't work i set the table like this :

m_pPlayListMiniItemDelegate =new PlayListMiniItemDelegate(this);
ui->PlayListMini_tableView->setSelectionBehavior(QAbstractItemView::SelectRows );
ui->PlayListMini_tableView->setSelectionMode(QAbstractItemView::SingleSelectio n);
ui->PlayListMini_tableView->setItemDelegate(m_pPlayListMiniItemDelegate);
ui->PlayListMini_tableView->setAlternatingRowColors(true);
ui->PlayListMini_tableView->setModel(PlayListMiniSqlModel::instance());
ui->PlayListMini_tableView->hideColumn(0);
ui->PlayListMini_tableView->hideColumn(1);

and inside the PlayListMiniSqlModel::instance()
i execute simple sql that returns 3 results in a row.
"SELECT foo1,foo2,foo3 FROM tbl"
the hide column 0,1 dosnt work i still see 3 column in raw.
also i follow this tutorial :
http://www.jwdougherty.com/content/qtableview-primary-keys-and-user-interfaces

wysota
2nd April 2012, 14:00
Show us your model implementation, please.

ChrisW67
2nd April 2012, 23:35
i execute simple sql that returns 3 results in a row.
"SELECT foo1,foo2,foo3 FROM tbl"
the hide column 0,1 dosnt work i still see 3 column in raw.

Ah yes... and that is a problem because...?