Results 1 to 20 of 26

Thread: Refresh QDataTable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Refresh QDataTable

    main.cpp is as under :
    Qt Code:
    1. #include <qapplication.h>
    2. #include "loginfrm.h"
    3. #include "editfrm.h"
    4. #include<qsqldatabase.h>
    5. #include<qstring.h>
    6. #include <qthread.h>
    7. #include <stdlib.h>
    8. #include <qwidget.h>
    9. #include <qtimer.h>
    10.  
    11. int main( int argc, char **argv )
    12. {
    13. QApplication a( argc, argv );
    14. QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL3");
    15. db->setDatabaseName("logindb");
    16. db->setUserName("root");
    17. db->setPassword("");
    18. db->setHostName("localhost");
    19. db->open();
    20. if ( !db->open())
    21. {
    22. qWarning(" database connection no thayu ");
    23. }
    24.  
    25. editfrm efrm;
    26.  
    27. a.setMainWidget( &efrm );
    28.  
    29. efrm.show();
    30. qWarning("waiting for login");
    31. qWarning("creating timer");
    32. QTimer *timer = new QTimer( &efrm , "mt" );
    33. efrm.connect( timer, SIGNAL(timeout()), SLOT(refreshTable()) );
    34. timer->start( 5000, FALSE ); /* 3 seconds single-shot timer 3000 */
    35. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    36.  
    37. qWarning("Leaving main");
    38. return a.exec();
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 
    NOTE : the editfrm gets some of its values from loginfrm because it is loaded first. but for the ease of understanding i have directly called editfrm from the main. It might be incorrect from the implementation point of view but it is absolutely correct logically. The loginfrm does nothing but initializes some global variables so that editfrm can use it. In the actual code the loginfrm is loaded first and then if the login is correct then the editfrm is loaded. It is only here that i have changed main function to show() the editfrm directly.

    editfrm.ui.h is as follows :
    Qt Code:
    1. #include<qapplication.h>
    2. #include<qsqldatabase.h>
    3. #include "loginfrm.h"
    4. #include "modifyfrm.h"
    5. #include <qwidget.h>
    6. #include<qdatatable.h>
    7. #include <qtimer.h>
    8. #include<qthread.h>
    9. #include <qobject.h>
    10. #include <qtable.h>
    11. #include <qsqlcursor.h>
    12.  
    13. static int btn;
    14. static int i=0;
    15.  
    16. void editfrm::initvalues()
    17. {
    18.  
    19. loginfrm *lfrm = new loginfrm();
    20.  
    21. if ( lfrm->check())
    22. {
    23. PB_add->setEnabled(TRUE);
    24. PB_edit->setEnabled(TRUE);
    25. PB_delete->setEnabled(TRUE);
    26. }
    27. else
    28. {
    29. PB_add->setEnabled(FALSE);
    30. PB_edit->setEnabled(FALSE);
    31. PB_delete->setEnabled(FALSE);
    32. }
    33.  
    34. }
    35.  
    36.  
    37. void editfrm::addclicked()
    38. {
    39. btn=1;
    40. modifyfrm *mfrm = new modifyfrm();
    41. mfrm->initvalues();
    42. hide();
    43. mfrm->show();
    44. }
    45.  
    46.  
    47. void editfrm::editclicked()
    48. {
    49.  
    50. btn=2;
    51. modifyfrm *mfrm = new modifyfrm();
    52. mfrm->initvalues();
    53. hide();
    54. mfrm->show();
    55. }
    56.  
    57.  
    58. void editfrm::deleteclicked()
    59. {
    60. btn=3;
    61. modifyfrm *mfrm = new modifyfrm();
    62. mfrm->initvalues();
    63. hide();
    64. mfrm->show();
    65. }
    66.  
    67. int editfrm::checkbtn()
    68. {
    69. return btn;
    70. }
    71.  
    72. void editfrm::cancelclicked()
    73. {
    74. loginfrm *lfrm = new loginfrm(this);
    75. hide();
    76. lfrm->show();
    77. }
    78.  
    79. void editfrm::refreshTable()
    80. {
    81. QString swar="";
    82. swar.sprintf("tick tick %d",i);
    83. qWarning(swar);
    84. dataTable1->update();
    85. dataTable1->repaint(true);
    86. dataTable1->refresh(QDataTable::RefreshAll);
    87. update();
    88. i++;
    89. }
    To copy to clipboard, switch view to plain text mode 
    as per the timer after every 3 secs "tick tick i " is printed but the datatable is not getting updated or refreshed.
    as u can see i have tried out with update(), repaint(), refresh(), none of which is working here. the datatable is failing to show the updated database. The database is getting updated from another GUI which is out of this project. I simultaneously run both the project 's GUI and after making changes in the database from one GUI in one project it doesnt get showed in the GUI of another project.

    i hope atleast now the picture is very much clear.
    please help me solve this problem

    thanks and regards
    shamik
    Last edited by jacek; 28th November 2006 at 10:19. Reason: missing [code] tags

Similar Threads

  1. row QDataTable
    By cristiano in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 17:07
  2. Replies: 9
    Last Post: 7th November 2006, 15:10
  3. QDataTable Inserts and Updates
    By ederbs in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 23:23
  4. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  5. Refreshing QDataTable
    By zlatko in forum Qt Programming
    Replies: 5
    Last Post: 2nd May 2006, 16:11

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.