Results 1 to 4 of 4

Thread: How to start an action at application launch ?

  1. #1
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

    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 

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  3. #3
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to start an action at application launch ?

    Hi caduel !

    Thats what i thought...

    It worked perfect.

    Many thanks,

    Fassage

  4. #4
    Join Date
    Apr 2009
    Posts
    20
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to start an action at application launch ?

    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 

Similar Threads

  1. How to start external application from QT?
    By TomASS in forum Newbie
    Replies: 10
    Last Post: 7th November 2009, 17:57
  2. Start Qt application as Windows Service
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 10th May 2008, 17:23
  3. Replies: 10
    Last Post: 10th March 2008, 12:28
  4. start application: Why this error and how to solve it?
    By Colx007 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2008, 15:22
  5. Replies: 2
    Last Post: 20th November 2007, 20:00

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.