PDA

View Full Version : qdatatable problem..



triperzonak
24th July 2008, 08:55
hi QT3 prob,
im trying to use qdatatable::setfilter function in setting up limit in the table view (like i will only show 50 records) setfilter("ID is not NULL LIMIT 50").. this is working however when i try to sort the table from the "columnclicked", it appends "order by" command to my filter which is not valid because i use "limit", so after creating the table i set back the filter to "NULL" but it gets now all the record to my table? how to solve this?

i thought that records qdatatable depends on the qsqlcursor because of dataTable->setSqlCursor( cursor, FALSE, TRUE); so i set the
cursor->setFilter ("ID is not NULL LIMIT 50") but nothing happens qdatatable still gets all the data from the table..

heres my code:


dataTable->addColumn( "ID", tr( "ID" ) );
dataTable->addColumn( "NAME", tr( "NAME" ) );
dataTable->setFilter( tr("ID is not null LIMIT 50") );
dataTable->setReadOnly( TRUE );
dataTable->setSorting( TRUE ); // I need this
if ( dataTable1 ) {
QSqlCursor* cursor = dataTable->sqlCursor();
if ( !cursor ) {
cursor = new QSqlCursor("myTable");
cursor->setFilter("ID is not null LIMIT 50"); // limiting cursor to 50, i think this is not working..

if ( dataTable->isReadOnly() )
cursor->setMode( QSqlCursor::ReadOnly );
dataTable->setSqlCursor( cursor, FALSE, TRUE);
}
if ( !cursor->isActive() )
dataTable->refresh( QDataTable::RefreshAll );
}
dataTable->setFilter(NULL); // set back the filter to NULL to avoid sql syntax error when sort column was clicked

jacek
28th July 2008, 14:50
Since you have a read-only data table, you can use QSqlSelectCursor with any query you want.