Results 1 to 3 of 3

Thread: Onde datatable with difirent cursors

  1. #1
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default One datatable with difirent cursors

    I have one datatable object and want in diffirent cases show results from diffirent sql cursors..is that good way? I try it but it doesnt work,becouse after first showing i cannot add another columns and delete previous for second showing..

    Qt Code:
    1. void QFormAdmin::OnPhysicTbPressed(int nId)
    2. {
    3. int nCols = dtMain->numCols();
    4. int nRows = dtMain->numRows();
    5.  
    6. // try to clean data table
    7. for (int i=0; i<nCols; i++)
    8. dtMain->removeColumn(0);
    9.  
    10. for (int i=0; i<nRows; i++)
    11. dtMain->removeRow(0);
    12.  
    13. dtMain->repaint();
    14.  
    15. switch(nId)
    16. {
    17. // виклик редактора гілок
    18. case 1:
    19. {
    20. QSqlSelectCursor* curBr = new QSqlSelectCursor( "SELECT deleted FROM branches");
    21.  
    22. dtMain->setSqlCursor(curBr,false,true );
    23.  
    24. dtMain->addColumn("deleted", tr("Імя1"));
    25.  
    26. dtMain->refresh();
    27. break;
    28. }
    29.  
    30. // виклик редактора контролерів
    31. case 2:
    32. {
    33. QSqlSelectCursor* curCtl = new QSqlSelectCursor( "SELECT controlers.description,controlers.logical_id,controlers.physical_id,controlers.active,controlers.branch,branches.description AS br_name,branches.port,branches.ip_address FROM controlers \
    34. LEFT JOIN branches ON controlers.branch = branches.id");
    35.  
    36. dtMain->setSqlCursor(curCtl,false,true );
    37.  
    38. dtMain->addColumn("description", tr("Імя"));
    39. dtMain->addColumn("logical_id", tr("Логічний №"));
    40. dtMain->addColumn("physical_id", tr("Фізичний №"));
    41. dtMain->addColumn("active", tr("Активний"));
    42. dtMain->addColumn("br_name", tr("Імя вітки"));
    43. dtMain->addColumn("port", tr("Порт"));
    44. dtMain->addColumn("ip_address", tr("IP-адрес"));
    45.  
    46. dtMain->refresh();
    47. break;
    48. }
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 

    After first call i have case 1 and see one columns in datatable. After second call i have case 2: and i create 7 columns but i see one previous column with new data
    Any suggestions pls...
    Last edited by zlatko; 28th April 2006 at 10:12.
    a life without programming is like an empty bottle

  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: One datatable with difirent cursors

    Try:
    Qt Code:
    1. void QFormAdmin::OnPhysicTbPressed(int nId)
    2. {
    3. // Do, or do not. There is no try. ;)
    4. const int nCols = dtMain->numCols();
    5. for (int i=0; i<nCols; i++) {
    6. dtMain->removeColumn(0);
    7. }
    8.  
    9. switch(nId)
    10. {
    11. // виклик редактора гілок
    12. case 1:
    13. {
    14. QSqlSelectCursor* curBr = new QSqlSelectCursor( ... );
    15.  
    16. dtMain->setSqlCursor(curBr,false,true );
    17.  
    18. dtMain->addColumn("deleted", tr("Імя1"));
    19.  
    20. dtMain->refresh( QDataTable::RefreshAll );
    21. break;
    22. }
    23.  
    24. // виклик редактора контролерів
    25. case 2:
    26. {
    27. QSqlSelectCursor* curCtl = new QSqlSelectCursor( ... );
    28.  
    29. dtMain->setSqlCursor(curCtl,false,true );
    30.  
    31. dtMain->addColumn("description", tr("Імя"));
    32. ...
    33. dtMain->addColumn("ip_address", tr("IP-адрес"));
    34.  
    35. dtMain->refresh( QDataTable::RefreshAll );
    36. break;
    37. }
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    zlatko (28th April 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Onde datatable with difirent cursors

    Emm..my stupid thoughtlessness
    Ok thanks its work perfect with remove
    a life without programming is like an empty bottle

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.