Hi All,

I have successfully implemented the progress bar example below but would like to eliminate the need for the start button !

I would like the progressBar to start as soon as the application is launched & close when the progress bar has been completed ??

Is this possible ? Can you please give a little detialed answers of how to implement this please ?

Many thanks in advance,

Fassage

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