Results 1 to 2 of 2

Thread: qdatatable problem..

  1. #1
    Join Date
    Dec 2007
    Posts
    129
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default qdatatable problem..

    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:
    Qt Code:
    1. dataTable->addColumn( "ID", tr( "ID" ) );
    2. dataTable->addColumn( "NAME", tr( "NAME" ) );
    3. dataTable->setFilter( tr("ID is not null LIMIT 50") );
    4. dataTable->setReadOnly( TRUE );
    5. dataTable->setSorting( TRUE ); // I need this
    6. if ( dataTable1 ) {
    7. QSqlCursor* cursor = dataTable->sqlCursor();
    8. if ( !cursor ) {
    9. cursor = new QSqlCursor("myTable");
    10. cursor->setFilter("ID is not null LIMIT 50"); // limiting cursor to 50, i think this is not working..
    11.  
    12. if ( dataTable->isReadOnly() )
    13. cursor->setMode( QSqlCursor::ReadOnly );
    14. dataTable->setSqlCursor( cursor, FALSE, TRUE);
    15. }
    16. if ( !cursor->isActive() )
    17. dataTable->refresh( QDataTable::RefreshAll );
    18. }
    19. dataTable->setFilter(NULL); // set back the filter to NULL to avoid sql syntax error when sort column was clicked
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qdatatable problem..

    Since you have a read-only data table, you can use QSqlSelectCursor with any query you want.

Similar Threads

  1. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  2. QDataTable problem
    By ederbs in forum Qt Programming
    Replies: 12
    Last Post: 8th February 2007, 23:47
  3. QDataTable problem in the order
    By cristiano in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2007, 22:58
  4. problem with QDataTable
    By zlatko in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2006, 15:31
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.