#include <QtCore/QCoreApplication>
#include "mythread.h"
......int main(int argc, char *argv[])
{
for (int i=0; i < 1000; i++)
{
MyThread * thread = new MyThread(i, app);
MyThread::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
MyThread::connect(thread, SIGNAL(terminated()), thread, SLOT(deleteLater()));
thread->start();
}
return a.exec();
}
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QtCore/QThread>
{
Q_OBJECT
public:
explicit MyThread
(int number,
QObject *parent
= 0);
void run();
private:
int number;
signals:
public slots:
};
#endif // MYTHREAD_H
#include "mythread.h"
#include <stdio.h>
MyThread
::MyThread(int number,
QObject *parent
) :{
}
void MyThread::run()
{
while (true)
{
//printf("Running thread number: %d\n", number);
}
}
#include <QtCore/QCoreApplication>
#include "mythread.h"
......int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication * app = qApp;
for (int i=0; i < 1000; i++)
{
MyThread * thread = new MyThread(i, app);
MyThread::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
MyThread::connect(thread, SIGNAL(terminated()), thread, SLOT(deleteLater()));
thread->start();
}
return a.exec();
}
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QtCore/QThread>
class MyThread : public QThread
{
Q_OBJECT
public:
explicit MyThread(int number, QObject *parent = 0);
void run();
private:
int number;
signals:
public slots:
};
#endif // MYTHREAD_H
#include "mythread.h"
#include <stdio.h>
MyThread::MyThread(int number, QObject *parent) :
QThread(parent), number(number)
{
}
void MyThread::run()
{
while (true)
{
//printf("Running thread number: %d\n", number);
QThread::msleep(10000);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks