fassage
3rd November 2009, 12:41
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
************************************************** **************************/
#ifndef FORM1_H
#define FORM1_H
#include <qdialog.h>
#include <qtimer.h>
class QProgressBar;
class QPushButton;
class Form1 : public QDialog
{
Q_OBJECT
public:
Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Form1();
QPushButton *sb;
QProgressBar* pb;
QTimer timer;
protected slots:
void myiter();
void mystart();
};
#endif // FORM1_H
************************************************** **************************/
#include "form1.h"
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <qtimer.h>
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl )
{
sb = new QPushButton( "&Start", this );
pb = new QProgressBar( this );
pb->setGeometry( QRect( 100, 0, 500, 30 ) );
pb->setTotalSteps( 10 );
pb->reset();
connect( sb, SIGNAL( clicked() ), this, SLOT( mystart() ) );
connect( &timer, SIGNAL( timeout() ), this, SLOT( myiter() ) );
}
Form1::~Form1() {};
void Form1::mystart() { if ( !timer.isActive() ) { timer.start(400); } else { timer.stop(); } }
void Form1::myiter() { int i = pb->progress(); pb->setProgress( ++i ); }
#include <qapplication.h>
#include "form1.h"
************************************************** **************************/
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Form1 w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
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
************************************************** **************************/
#ifndef FORM1_H
#define FORM1_H
#include <qdialog.h>
#include <qtimer.h>
class QProgressBar;
class QPushButton;
class Form1 : public QDialog
{
Q_OBJECT
public:
Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Form1();
QPushButton *sb;
QProgressBar* pb;
QTimer timer;
protected slots:
void myiter();
void mystart();
};
#endif // FORM1_H
************************************************** **************************/
#include "form1.h"
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <qtimer.h>
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl )
{
sb = new QPushButton( "&Start", this );
pb = new QProgressBar( this );
pb->setGeometry( QRect( 100, 0, 500, 30 ) );
pb->setTotalSteps( 10 );
pb->reset();
connect( sb, SIGNAL( clicked() ), this, SLOT( mystart() ) );
connect( &timer, SIGNAL( timeout() ), this, SLOT( myiter() ) );
}
Form1::~Form1() {};
void Form1::mystart() { if ( !timer.isActive() ) { timer.start(400); } else { timer.stop(); } }
void Form1::myiter() { int i = pb->progress(); pb->setProgress( ++i ); }
#include <qapplication.h>
#include "form1.h"
************************************************** **************************/
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Form1 w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}