Progress Bar: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Progress Bar=
[[Category:HowTo]]<br />[[Category:Snippets]]<br />[[Category:Tutorial]]


It is often necessary to display a progress bar while a long operation is happening. The case we are concerned about in this example is when there is no easy way to track the progress of the operation – all that is known is when it is done. There are many ways to do this. You could use a progressBar widget on your widget and run the operation in a different thread (using moveToThread()). This typically requires a special object to be created (a subclass of [http://developer.qt.nokia.com/doc/qt-4.8/qobject.html QObject] ''[developer.qt.nokia.com]'' that runs the operation and then emits a finished() signal), which can be a pain if you need to do this for many different operations.
[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]


However, using [http://developer.qt.nokia.com/doc/qt-4.8/qfuturewatcher.html QFutureWatcher] ''[developer.qt.nokia.com]'' and [http://developer.qt.nokia.com/doc/qt-4.8/qtconcurrentrun.html#run QtConcurrent::run()] ''[developer.qt.nokia.com]'', this is extremely easy. Below we demonstrate how to use this technique with both a QProgressDialog and a QProgressBar.
= Progress Bar =


==QProgressBar Example==
It is often necessary to display a progress bar while a long operation is happening. The case we are concerned about in this example is when there is no easy way to track the progress of the operation - all that is known is when it is done. There are many ways to do this. You could use a progressBar widget on your widget and run the operation in a different thread (using moveToThread()). This typically requires a special object to be created (a subclass of &quot;QObject&amp;quot;:http://developer.qt.nokia.com/doc/qt-4.8/qobject.html that runs the operation and then emits a finished() signal), which can be a pain if you need to do this for many different operations.


===form.h===
However, using &quot;QFutureWatcher&amp;quot;:http://developer.qt.nokia.com/doc/qt-4.8/qfuturewatcher.html and &quot;QtConcurrent::run()&quot;:http://developer.qt.nokia.com/doc/qt-4.8/qtconcurrentrun.html#run, this is extremely easy. Below we demonstrate how to use this technique with both a QProgressDialog and a QProgressBar.


===form.cpp===
== QProgressBar Example ==


===form.ui===
=== form.h ===


===FutureWatcher.cpp===
<code>#ifndef FORM_H<br />#define FORM_H


===MyClass.h===
#include &quot;ui_form.h&amp;quot;


===CMakeLists.txt===
#include &lt;QFutureWatcher&amp;gt;


==QProgressDialog Example==
#include &quot;MyClass.h&amp;quot;


===form.h===
class Form : public QWidget, private Ui::Form<br />{<br />Q_OBJECT


===form.cpp===
public slots:


===form.ui===
void slot_finished();<br /> void on_pushButton_clicked();


MyClass.h<br />
public:<br /> Form(QWidget *parent = 0);


===FutureWatcherProgressDialog.cpp===
private:<br /> QFutureWatcher&amp;lt;void&amp;gt; FutureWatcher;<br /> MyClass MyObject;<br />};


===Categories:===
#endif<br /></code>


* [[:Category:HowTo|HowTo]]
=== form.cpp ===
* [[:Category:snippets|snippets]]
 
* [[:Category:Tutorial|Tutorial]]
<code><br />#include &lt;QtGui&amp;gt;<br />#include &lt;QImage&amp;gt;
 
#include &quot;form.h&amp;quot;
 
#include &lt;iostream&amp;gt;
 
Form::Form(QWidget *parent)<br /> : QWidget(parent)<br />{<br /> setupUi(this);
 
this-&gt;progressBar-&gt;setMinimum(0);<br /> this-&gt;progressBar-&gt;setMaximum(0);<br /> this-&gt;progressBar-&gt;hide();
 
connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this, SLOT (slot_finished()));
 
}
 
void Form::slot_finished()<br />{<br /> this-&gt;progressBar-&gt;hide();<br />}
 
void Form::on_pushButton_clicked()<br />{<br /> this-&gt;progressBar-&gt;show();
 
// Start the computation.<br /> QFuture&amp;lt;void&amp;gt; future = QtConcurrent::run(&amp;this-&gt;MyObject, &amp;MyClass::LongFunction);<br /> this-&gt;FutureWatcher.setFuture(future);<br />}<br /></code>
 
=== form.ui ===
 
<code><br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;UTF-8&amp;quot;?&amp;gt;<br />&lt;ui version=&quot;4.0&amp;quot;&gt;<br /> &lt;class&amp;gt;Form&amp;lt;/class&amp;gt;<br /> &lt;widget class=&quot;QWidget&amp;quot; name=&quot;Form&amp;quot;&gt;<br /> &lt;property name=&quot;geometry&amp;quot;&gt;<br /> &lt;rect&amp;gt;<br /> &lt;x&amp;gt;0&amp;lt;/x&amp;gt;<br /> &lt;y&amp;gt;0&amp;lt;/y&amp;gt;<br /> &lt;width&amp;gt;400&amp;lt;/width&amp;gt;<br /> &lt;height&amp;gt;300&amp;lt;/height&amp;gt;<br /> &lt;/rect&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;property name=&quot;windowTitle&amp;quot;&gt;<br /> &lt;string&amp;gt;Form&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;layout class=&quot;QVBoxLayout&amp;quot; name=&quot;verticalLayout&amp;quot;&gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QPushButton&amp;quot; name=&quot;pushButton&amp;quot;&gt;<br /> &lt;property name=&quot;text&amp;quot;&gt;<br /> &lt;string&amp;gt;PushButton&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QLineEdit&amp;quot; name=&quot;lineEdit&amp;quot;/&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QProgressBar&amp;quot; name=&quot;progressBar&amp;quot;&gt;<br /> &lt;property name=&quot;value&amp;quot;&gt;<br /> &lt;number&amp;gt;24&amp;lt;/number&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;/layout&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;resources/&amp;gt;<br /> &lt;connections/&amp;gt;<br />&lt;/ui&amp;gt;<br /></code>
 
=== FutureWatcher.cpp ===
 
<code>#include &lt;QApplication&amp;gt;<br />#include &lt;QObject&amp;gt;<br />#include &lt;QThread&amp;gt;
 
#include &lt;iostream&amp;gt;
 
#include &quot;form.h&amp;quot;
 
int main(int argc, char*argv[])<br />{<br /> QApplication app(argc, argv);
 
Form form;
 
form.show();
 
return app.exec&amp;amp;#40;&amp;#41;;<br />}</code>
 
=== MyClass.h ===
 
<code><br />#ifndef MyClass_H<br />#define MyClass_H
 
#include &lt;iostream&amp;gt;
 
class MyClass<br />{<br />public:
 
void LongFunction()<br /> {<br /> for( int count = 0; count &lt; 5; count++ )<br /> {<br /> sleep( 1 );<br /> std::cout &lt;&lt; &quot;Ping long!&quot; &lt;&lt; std::endl;<br /> }<br /> }<br />};
 
#endif<br /></code>
 
=== CMakeLists.txt ===
 
<code><br />cmake_minimum_required(VERSION 2.6)
 
PROJECT (FutureWatcher)
 
FIND_PACKAGE(Qt4 REQUIRED)<br />INCLUDE ($&amp;#123;QT_USE_FILE&amp;#125;)
 
QT4_WRAP_CPP(MOCSrcs form.h)<br />QT4_WRAP_UI(UISrcs form.ui)
 
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
 
ADD_EXECUTABLE(FutureWatcher FutureWatcher.cpp MyClass.cpp form.cpp ${MOCSrcs} ${UISrcs})<br />TARGET_LINK_LIBRARIES(FutureWatcher ${QT_LIBRARIES})<br /></code>
 
== QProgressDialog Example ==
 
=== form.h ===
 
<code><br />#ifndef FORM_H<br />#define FORM_H
 
#include &quot;ui_form.h&amp;quot;
 
#include &lt;QFutureWatcher&amp;gt;
 
#include &quot;MyClass.h&amp;quot;
 
class QProgressDialog;
 
class Form : public QWidget, private Ui::Form<br />{<br />Q_OBJECT
 
public slots:
 
void slot_finished();<br /> void on_pushButton_clicked();
 
public:<br /> Form(QWidget '''parent = 0);
<br />private:<br /> QFutureWatcher&amp;lt;void&amp;gt; FutureWatcher;<br /> MyClass MyObject;<br /> QProgressDialog''' ProgressDialog;<br />};
 
#endif<br /></code>
 
=== form.cpp ===
 
<code><br />#include &lt;QtGui&amp;gt;<br />#include &lt;QImage&amp;gt;
 
#include &quot;form.h&amp;quot;
 
#include &lt;iostream&amp;gt;
 
Form::Form(QWidget *parent)<br /> : QWidget(parent)<br />{<br /> setupUi(this);
 
this-&gt;ProgressDialog = new QProgressDialog(this);
 
connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this, SLOT (slot_finished()));<br /> connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this-&gt;ProgressDialog , SLOT (cancel()));
 
}
 
void Form::slot_finished()<br />{<br /> std::cout &lt;&lt; &quot;Finshed&amp;quot; &lt;&lt; std::endl;<br />}
 
void Form::on_pushButton_clicked()<br />{<br /> // Start the computation.<br /> QFuture&amp;lt;void&amp;gt; future = QtConcurrent::run(&amp;this-&gt;MyObject, &amp;MyClass::LongFunction);<br /> this-&gt;FutureWatcher.setFuture(future);
 
this-&gt;ProgressDialog-&gt;setMinimum(0);<br /> this-&gt;ProgressDialog-&gt;setMaximum(0);<br /> this-&gt;ProgressDialog-&gt;setWindowModality(Qt::WindowModal);<br /> this-&gt;ProgressDialog-&gt;exec&amp;amp;#40;&amp;#41;;
 
}<br /></code>
 
=== form.ui ===
 
<code><br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;UTF-8&amp;quot;?&amp;gt;<br />&lt;ui version=&quot;4.0&amp;quot;&gt;<br /> &lt;class&amp;gt;Form&amp;lt;/class&amp;gt;<br /> &lt;widget class=&quot;QWidget&amp;quot; name=&quot;Form&amp;quot;&gt;<br /> &lt;property name=&quot;geometry&amp;quot;&gt;<br /> &lt;rect&amp;gt;<br /> &lt;x&amp;gt;0&amp;lt;/x&amp;gt;<br /> &lt;y&amp;gt;0&amp;lt;/y&amp;gt;<br /> &lt;width&amp;gt;400&amp;lt;/width&amp;gt;<br /> &lt;height&amp;gt;300&amp;lt;/height&amp;gt;<br /> &lt;/rect&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;property name=&quot;windowTitle&amp;quot;&gt;<br /> &lt;string&amp;gt;Form&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;layout class=&quot;QVBoxLayout&amp;quot; name=&quot;verticalLayout&amp;quot;&gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QPushButton&amp;quot; name=&quot;pushButton&amp;quot;&gt;<br /> &lt;property name=&quot;text&amp;quot;&gt;<br /> &lt;string&amp;gt;PushButton&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;/layout&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;resources/&amp;gt;<br /> &lt;connections/&amp;gt;<br />&lt;/ui&amp;gt;<br /></code>
 
MyClass.h<br /><code><br />#ifndef MyClass_H<br />#define MyClass_H
 
#include &lt;iostream&amp;gt;
 
class MyClass<br />{<br />public:
 
void LongFunction()<br /> {<br /> for( int count = 0; count &lt; 5; count++ )<br /> {<br /> sleep( 1 );<br /> std::cout &lt;&lt; &quot;Ping long!&quot; &lt;&lt; std::endl;<br /> }<br /> }<br />};
 
#endif<br /></code>
 
=== FutureWatcherProgressDialog.cpp ===
 
<code>#include &lt;QApplication&amp;gt;<br />#include &lt;QObject&amp;gt;<br />#include &lt;QThread&amp;gt;
 
#include &lt;iostream&amp;gt;
 
#include &quot;form.h&amp;quot;
 
int main(int argc, char*argv[])<br />{<br /> QApplication app(argc, argv);
 
Form form;
 
form.show();
 
return app.exec&amp;amp;#40;&amp;#41;;

Revision as of 14:22, 23 February 2015



[toc align_right="yes&quot; depth="3&quot;]

Progress Bar

It is often necessary to display a progress bar while a long operation is happening. The case we are concerned about in this example is when there is no easy way to track the progress of the operation - all that is known is when it is done. There are many ways to do this. You could use a progressBar widget on your widget and run the operation in a different thread (using moveToThread()). This typically requires a special object to be created (a subclass of "QObject&quot;:http://developer.qt.nokia.com/doc/qt-4.8/qobject.html that runs the operation and then emits a finished() signal), which can be a pain if you need to do this for many different operations.

However, using "QFutureWatcher&quot;:http://developer.qt.nokia.com/doc/qt-4.8/qfuturewatcher.html and "QtConcurrent::run()":http://developer.qt.nokia.com/doc/qt-4.8/qtconcurrentrun.html#run, this is extremely easy. Below we demonstrate how to use this technique with both a QProgressDialog and a QProgressBar.

QProgressBar Example

form.h

#ifndef FORM_H<br />#define FORM_H

#include &quot;ui_form.h&amp;quot;

#include &lt;QFutureWatcher&amp;gt;

#include &quot;MyClass.h&amp;quot;

class Form : public QWidget, private Ui::Form<br />{<br />Q_OBJECT

public slots:

void slot_finished();<br /> void on_pushButton_clicked();

public:<br /> Form(QWidget *parent = 0);

private:<br /> QFutureWatcher&amp;lt;void&amp;gt; FutureWatcher;<br /> MyClass MyObject;<br />};

#endif<br />

form.cpp

<br />#include &lt;QtGui&amp;gt;<br />#include &lt;QImage&amp;gt;

#include &quot;form.h&amp;quot;

#include &lt;iostream&amp;gt;

Form::Form(QWidget *parent)<br /> : QWidget(parent)<br />{<br /> setupUi(this);

this-&gt;progressBar-&gt;setMinimum(0);<br /> this-&gt;progressBar-&gt;setMaximum(0);<br /> this-&gt;progressBar-&gt;hide();

connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this, SLOT (slot_finished()));

}

void Form::slot_finished()<br />{<br /> this-&gt;progressBar-&gt;hide();<br />}

void Form::on_pushButton_clicked()<br />{<br /> this-&gt;progressBar-&gt;show();

// Start the computation.<br /> QFuture&amp;lt;void&amp;gt; future = QtConcurrent::run(&amp;this-&gt;MyObject, &amp;MyClass::LongFunction);<br /> this-&gt;FutureWatcher.setFuture(future);<br />}<br />

form.ui

<br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;UTF-8&amp;quot;?&amp;gt;<br />&lt;ui version=&quot;4.0&amp;quot;&gt;<br /> &lt;class&amp;gt;Form&amp;lt;/class&amp;gt;<br /> &lt;widget class=&quot;QWidget&amp;quot; name=&quot;Form&amp;quot;&gt;<br /> &lt;property name=&quot;geometry&amp;quot;&gt;<br /> &lt;rect&amp;gt;<br /> &lt;x&amp;gt;0&amp;lt;/x&amp;gt;<br /> &lt;y&amp;gt;0&amp;lt;/y&amp;gt;<br /> &lt;width&amp;gt;400&amp;lt;/width&amp;gt;<br /> &lt;height&amp;gt;300&amp;lt;/height&amp;gt;<br /> &lt;/rect&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;property name=&quot;windowTitle&amp;quot;&gt;<br /> &lt;string&amp;gt;Form&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;layout class=&quot;QVBoxLayout&amp;quot; name=&quot;verticalLayout&amp;quot;&gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QPushButton&amp;quot; name=&quot;pushButton&amp;quot;&gt;<br /> &lt;property name=&quot;text&amp;quot;&gt;<br /> &lt;string&amp;gt;PushButton&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QLineEdit&amp;quot; name=&quot;lineEdit&amp;quot;/&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QProgressBar&amp;quot; name=&quot;progressBar&amp;quot;&gt;<br /> &lt;property name=&quot;value&amp;quot;&gt;<br /> &lt;number&amp;gt;24&amp;lt;/number&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;/layout&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;resources/&amp;gt;<br /> &lt;connections/&amp;gt;<br />&lt;/ui&amp;gt;<br />

FutureWatcher.cpp

#include &lt;QApplication&amp;gt;<br />#include &lt;QObject&amp;gt;<br />#include &lt;QThread&amp;gt;

#include &lt;iostream&amp;gt;

#include &quot;form.h&amp;quot;

int main(int argc, char*argv[])<br />{<br /> QApplication app(argc, argv);

Form form;

form.show();

return app.exec&amp;amp;#40;&amp;#41;;<br />}

MyClass.h

<br />#ifndef MyClass_H<br />#define MyClass_H

#include &lt;iostream&amp;gt;

class MyClass<br />{<br />public:

void LongFunction()<br /> {<br /> for( int count = 0; count &lt; 5; count++ )<br /> {<br /> sleep( 1 );<br /> std::cout &lt;&lt; &quot;Ping long!&quot; &lt;&lt; std::endl;<br /> }<br /> }<br />};

#endif<br />

CMakeLists.txt

<br />cmake_minimum_required(VERSION 2.6)

PROJECT (FutureWatcher)

FIND_PACKAGE(Qt4 REQUIRED)<br />INCLUDE ($&amp;#123;QT_USE_FILE&amp;#125;)

QT4_WRAP_CPP(MOCSrcs form.h)<br />QT4_WRAP_UI(UISrcs form.ui)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

ADD_EXECUTABLE(FutureWatcher FutureWatcher.cpp MyClass.cpp form.cpp ${MOCSrcs} ${UISrcs})<br />TARGET_LINK_LIBRARIES(FutureWatcher ${QT_LIBRARIES})<br />

QProgressDialog Example

form.h

<br />#ifndef FORM_H<br />#define FORM_H

#include &quot;ui_form.h&amp;quot;

#include &lt;QFutureWatcher&amp;gt;

#include &quot;MyClass.h&amp;quot;

class QProgressDialog;

class Form : public QWidget, private Ui::Form<br />{<br />Q_OBJECT

public slots:

void slot_finished();<br /> void on_pushButton_clicked();

public:<br /> Form(QWidget '''parent = 0);
<br />private:<br /> QFutureWatcher&amp;lt;void&amp;gt; FutureWatcher;<br /> MyClass MyObject;<br /> QProgressDialog''' ProgressDialog;<br />};

#endif<br />

form.cpp

<br />#include &lt;QtGui&amp;gt;<br />#include &lt;QImage&amp;gt;

#include &quot;form.h&amp;quot;

#include &lt;iostream&amp;gt;

Form::Form(QWidget *parent)<br /> : QWidget(parent)<br />{<br /> setupUi(this);

this-&gt;ProgressDialog = new QProgressDialog(this);

connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this, SLOT (slot_finished()));<br /> connect(&amp;this-&gt;FutureWatcher, SIGNAL (finished()), this-&gt;ProgressDialog , SLOT (cancel()));

}

void Form::slot_finished()<br />{<br /> std::cout &lt;&lt; &quot;Finshed&amp;quot; &lt;&lt; std::endl;<br />}

void Form::on_pushButton_clicked()<br />{<br /> // Start the computation.<br /> QFuture&amp;lt;void&amp;gt; future = QtConcurrent::run(&amp;this-&gt;MyObject, &amp;MyClass::LongFunction);<br /> this-&gt;FutureWatcher.setFuture(future);

this-&gt;ProgressDialog-&gt;setMinimum(0);<br /> this-&gt;ProgressDialog-&gt;setMaximum(0);<br /> this-&gt;ProgressDialog-&gt;setWindowModality(Qt::WindowModal);<br /> this-&gt;ProgressDialog-&gt;exec&amp;amp;#40;&amp;#41;;

}<br />

form.ui

<br />&amp;lt;?xml version=&quot;1.0&amp;quot; encoding=&quot;UTF-8&amp;quot;?&amp;gt;<br />&lt;ui version=&quot;4.0&amp;quot;&gt;<br /> &lt;class&amp;gt;Form&amp;lt;/class&amp;gt;<br /> &lt;widget class=&quot;QWidget&amp;quot; name=&quot;Form&amp;quot;&gt;<br /> &lt;property name=&quot;geometry&amp;quot;&gt;<br /> &lt;rect&amp;gt;<br /> &lt;x&amp;gt;0&amp;lt;/x&amp;gt;<br /> &lt;y&amp;gt;0&amp;lt;/y&amp;gt;<br /> &lt;width&amp;gt;400&amp;lt;/width&amp;gt;<br /> &lt;height&amp;gt;300&amp;lt;/height&amp;gt;<br /> &lt;/rect&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;property name=&quot;windowTitle&amp;quot;&gt;<br /> &lt;string&amp;gt;Form&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;layout class=&quot;QVBoxLayout&amp;quot; name=&quot;verticalLayout&amp;quot;&gt;<br /> &lt;item&amp;gt;<br /> &lt;widget class=&quot;QPushButton&amp;quot; name=&quot;pushButton&amp;quot;&gt;<br /> &lt;property name=&quot;text&amp;quot;&gt;<br /> &lt;string&amp;gt;PushButton&amp;lt;/string&amp;gt;<br /> &lt;/property&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;/item&amp;gt;<br /> &lt;/layout&amp;gt;<br /> &lt;/widget&amp;gt;<br /> &lt;resources/&amp;gt;<br /> &lt;connections/&amp;gt;<br />&lt;/ui&amp;gt;<br />

MyClass.h

<br />#ifndef MyClass_H<br />#define MyClass_H

#include &lt;iostream&amp;gt;

class MyClass<br />{<br />public:

void LongFunction()<br /> {<br /> for( int count = 0; count &lt; 5; count++ )<br /> {<br /> sleep( 1 );<br /> std::cout &lt;&lt; &quot;Ping long!&quot; &lt;&lt; std::endl;<br /> }<br /> }<br />};

#endif<br />

FutureWatcherProgressDialog.cpp

#include <QApplication&gt;
#include <QObject&gt;
#include <QThread&gt;

  1. include <iostream&gt;
  1. include "form.h&quot;

int main(int argc, char*argv[])
{
QApplication app(argc, argv);

Form form;

form.show();

return app.exec&amp;#40;&#41;;