(1)用VC6.0新建个Win32 Console Application工程
(2)Project Settings里面Link标签页面添加qtmain.lib qt-mt320.lib
Project Settings里面C/C++标签页面添加QT_THREAD_SUPPORT
(3)源代码文件(main.cpp):
#include <qthread.h>
class MyThread : public QThread
{
public:
virtual void run();
};
void MyThread::run()
{
for( int count = 0; count < 20; count++ )
{
sleep( 1 );
qDebug( "Ping!" );
}
}
int main()
{
MyThread a;
MyThread b;
a.start();
b.start();
a.wait();
b.wait();
}
注释:
This will start two threads, each of which writes Ping! 20 times to the screen and exits.
The wait() calls at the end of main() are necessary because exiting main() ends the program,
unceremoniously killing all other threads.
Each MyThread stops executing when it reaches the end of MyThread::run(),
just as an application does when it leaves main().
(2)Project Settings里面Link标签页面添加qtmain.lib qt-mt320.lib
Project Settings里面C/C++标签页面添加QT_THREAD_SUPPORT
(3)源代码文件(main.cpp):
#include <qthread.h>
class MyThread : public QThread
{
public:
virtual void run();
};
void MyThread::run()
{
for( int count = 0; count < 20; count++ )
{
sleep( 1 );
qDebug( "Ping!" );
}
}
int main()
{
MyThread a;
MyThread b;
a.start();
b.start();
a.wait();
b.wait();
}
注释:
This will start two threads, each of which writes Ping! 20 times to the screen and exits.
The wait() calls at the end of main() are necessary because exiting main() ends the program,
unceremoniously killing all other threads.
Each MyThread stops executing when it reaches the end of MyThread::run(),
just as an application does when it leaves main().