Sorry forgot to post new working code for future beginners like myself !

Qt Code:
  1. ****************************************************************************/
  2.  
  3. #ifndef FORM1_H
  4. #define FORM1_H
  5.  
  6. #include <qdialog.h>
  7. #include <qtimer.h>
  8.  
  9.  
  10. class Form1 : public QDialog
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
  16. ~Form1();
  17.  
  18. QTimer timer;
  19.  
  20. protected slots:
  21. void myiter();
  22. };
  23.  
  24. #endif // FORM1_H
  25.  
  26. ****************************************************************************/
  27.  
  28. #include "form1.h"
  29. #include <qprogressbar.h>
  30. #include <qtimer.h>
  31.  
  32. Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl )
  33. {
  34. pb = new QProgressBar( this );
  35. pb->setGeometry( QRect( 0, 0, 500, 30 ) );
  36. pb->setTotalSteps( 10 );
  37. pb->reset();
  38.  
  39. connect( &timer, SIGNAL( timeout() ), this, SLOT( myiter() ) );
  40.  
  41. if ( !timer.isActive() ) { timer.start(400); } else { timer.stop(); }
  42. }
  43.  
  44. Form1::~Form1() {};
  45. void Form1::myiter() {
  46. int i = pb->progress();
  47. pb->setProgress( ++i );
  48. if ( i == pb->totalSteps() ) { close(); }
  49. }
  50.  
  51. ****************************************************************************/
  52. #include <qapplication.h>
  53. #include "form1.h"
  54.  
  55. int main( int argc, char ** argv )
  56. {
  57. QApplication a( argc, argv );
  58. Form1 w;
  59. w.show();
  60. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
  61. return a.exec();
  62. }
To copy to clipboard, switch view to plain text mode