Re: [TFUI] testing Qt code
Phlip <phlipcpp-/[email protected]>
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <[email protected]> |
> > Can you run processEvents in a loop?
David Dibben wrote:
> Yes. In fact this is its main use. The documented
> reason that
> processEvents exists is so that you can call it
> periodically during a long
> calculation to allow the gui to be refeshed or allow
> the user to cancel
> the calculation without having to resort to running
> the calculation in a
> separate thread. Something like:
>
> while (stuff_still_to_do) {
> do_some_stuff();
> qApp->processEvents();
> }
If that generally works it's the best way. You can
still test before, during, and after the loop spins.
You can also put a call to a window capture program in
the loop, assemble serieses of pictures into
animations, toss them onto a file server, and make the
executives review them first before calling.
> OK, a first attempt at this could look something
> like below. This code
> could almost certainly do with some improvement but
> it shows one way of
> doing it.
>
> After showing the window a local event loop is
> entered using
> qApp->enter_loop(); This allows full interaction to
> take place with the
> revealed window. To stop the interaction we need to
> call
> qApp->exit_loop();
> so the code below displays a second small dialog
> with a single push button
> which when pressed stops the interaction.
This pattern is good for development, and also very
clear in this GUI Toolkit. Other less fortunate ones
may have similar abilities, but when those are less
obvious, we need to add test fixtures to replicate
each method here.
> Of course, if you prefer to stop the interaction by
> killing the program
> you can simplify the code by just calling either
> qApp->enter_loop(); or
> qApp->exec() after showing the window. In this case
> you don't need to
> bother with the stop dialog. However, if you wanted
> to place tests _after_
> the call to reveal then clearly this won't be a
> suitable solution.
>
> #include <qdialog.h>
> #include <qapplication.h>
> #include <qpushbutton.h>
> #include <qlayout.h>
>
> // a simple dialog with a single push button.
> class StopDialog : public QDialog
> {
> Q_OBJECT
> public:
>
> StopDialog();
>
> public slots:
>
> void startInteration();
> void stopInteraction();
>
> private:
>
> QPushButton* fStopButton;
> bool fInLoop;
>
> };
>
> StopDialog::StopDialog()
> {
> // create a pushbutton to stop the interaction
> fStopButton = new QPushButton(this);
> fStopButton->setText("Stop Interaction");
>
> // Qt uses layouts to position the widgets
> QHBoxLayout* layout = new QHBoxLayout(this);
> layout->addWidget(fStopButton);
>
> // call the stopInteraction when the button is
> clicked
> connect(fStopButton, SIGNAL(clicked()), this,
> SLOT(stopInteraction()));
>
> fInLoop = false;
> }
>
> void StopDialog::stopInteraction()
> {
> if (fInLoop == true) {
> // exit the local event loop
> qApp->exit_loop();
> fInLoop = false;
> }
> }
>
> void StopDialog::startInteration()
> {
> if (fInLoop == false) {
> fInLoop = true;
> // enter a local event loop
> qApp->enter_loop();
> }
> }
>
>
> void revealInteractive(QWidget* widget)
> {
> // show the widget
> widget->show();
>
> // create a "stop" dialog box
> StopDialog dialog;
> // show the dialog
> dialog.show();
> // start interaction. This function call will only
> return when
> // stopInteraction has been called
> dialog.startInteration();
> }
>
>
> int main(int argc, char** argv)
> {
> QApplication app(argc, argv);
>
> //create an empty dialog object
> QDialog* dialog = new QDialog();
>
> // reveal the dialog
> revealInteractive(dialog);
>
>
> return EXIT_SUCCESS;
> }
>
> // everything in this example is in one file so we
> we need this line for
> // Qt's MOC system to work.
> #include "reveal.moc"
I left all that in to make certain it uses up more
space on the servers.
=====
Phlip
http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/nhFolB/TM
---------------------------------------------------------------------~->
To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/TestFirstUserInterfaces/
<*> To unsubscribe from this group, send an email to:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/