class DeviceScanner : public QThread{ Q_OBJECTprivate: const QVector<boost::shared_ptr<eNod3> >& Devices; int Interval;private slots: void slotTimeOut();signals: void Weighted(QString);private: void run();public: DeviceScanner(QObject *parent, const QVector<boost::shared_ptr<eNod3> >& devices, int interval); ~DeviceScanner();};DeviceScanner::DeviceScanner(QObject *parent, const QVector<boost::shared_ptr<eNod3> >& devices, int interval) : QThread(parent), Devices(devices), Interval(interval){ start();}DeviceScanner::~DeviceScanner(){ quit();}void DeviceScanner::slotTimeOut(){QString s;// Че-то там...emit Weighted( s );}void DeviceScanner::run(){ QTimer t; connect(&t, SIGNAL(timeout()), SLOT(slotTimeOut())); t.start(Interval); exec();}
connect(&t, SIGNAL(timeout()), SLOT(slotTimeOut()), Qt::DirectConnection);
class DeviceScanner : public QObject{ Q_OBJECTpublic: DeviceScanner( QObject *parent, const QVector<boost::shared_ptr<eNod3> >& devices ) : QObject(parent), devs(devices) {}public slots: void scan();signals: void weighted( const QString& );private: const QVector<boost::shared_ptr<eNod3> >& devs;};class DeviceThread : public QThread{ Q_OBJECTpublic: DeviceThread(QObject *parent, const QVector<boost::shared_ptr<eNod3> >& devices, int interval); ~DeviceScanner();signals: void Weighted( const QString& );private: const QVector<boost::shared_ptr<eNod3> >& Devices; int Interval; void run();};DeviceThread::DeviceThread(QObject *parent, const QVector<boost::shared_ptr<eNod3> >& devices, int interval) : QThread(parent), Devices(devices), Interval(interval){ start();}DeviceThread::~DeviceThread(){ quit();}void DeviceThread::run(){ QTimer timer; DeviceScanner scanner(0, Devices); connect(&timer, SIGNAL(timeout()), &scanner, SLOT(scan())); connect(&scanner, SIGNAL(weighted()), this, SIGNAL(Weighted())); timer.start(Interval); exec();}