How to start an action at application launch ?
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
Code:
****************************************************************************/
#ifndef FORM1_H
#define FORM1_H
#include <qdialog.h>
#include <qtimer.h>
{
Q_OBJECT
public:
Form1
( QWidget* parent
= 0,
const char* name
= 0,
bool modal
= FALSE, WFlags fl
= 0 );
~Form1();
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
){
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 )
{
Form1 w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
Re: How to start an action at application launch ?
just call mystart() in your constructor (or show()); and call close() (e.g. in myiter()) when you are done
Re: How to start an action at application launch ?
Hi caduel !
Thats what i thought...
It worked perfect.
Many thanks,
Fassage
Re: How to start an action at application launch ?
Sorry forgot to post new working code for future beginners like myself !
Code:
****************************************************************************/
#ifndef FORM1_H
#define FORM1_H
#include <qdialog.h>
#include <qtimer.h>
{
Q_OBJECT
public:
Form1
( QWidget* parent
= 0,
const char* name
= 0,
bool modal
= FALSE, WFlags fl
= 0 );
~Form1();
protected slots:
void myiter();
};
#endif // FORM1_H
****************************************************************************/
#include "form1.h"
#include <qprogressbar.h>
#include <qtimer.h>
Form1
::Form1( QWidget* parent,
const char* name,
bool modal, WFlags fl
) : QDialog( parent, name, modal, fl
){
pb
->setGeometry
( QRect( 0,
0,
500,
30 ) );
pb->setTotalSteps( 10 );
pb->reset();
connect( &timer, SIGNAL( timeout() ), this, SLOT( myiter() ) );
if ( !timer.isActive() ) { timer.start(400); } else { timer.stop(); }
}
Form1::~Form1() {};
void Form1::myiter() {
int i = pb->progress();
pb->setProgress( ++i );
if ( i == pb->totalSteps() ) { close(); }
}
****************************************************************************/
#include <qapplication.h>
#include "form1.h"
int main( int argc, char ** argv )
{
Form1 w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}