C++ (Qt) Thread = new MyThread; connect(Thread , SIGNAL(finished()), Thread , SLOT(deleteLater())); Thread->start();
C++ (Qt) Thread = new MyThread; connect(Thread , SIGNAL(finished()), MyWidget , SLOT(myThreadFinishedSlot())); Thread->start();
C++ (Qt)Potok::Potok(QWidget *parent) : QWidget(parent){ ui.setupUi(this); QObject::connect(ui.MyRun, SIGNAL(clicked()),this, SLOT(ZapuskThread()));}; void Potok::ZapuskThread (void) { Pt=new PotokThread((QObject*)this); connect(Pt , SIGNAL(finished()), Pt , SLOT(deleteLater())); QObject::connect(Pt, SIGNAL(valueChanged(int)), ui.Zapolnenie, SLOT(setValue(int)), Qt::QueuedConnection); Pt->start();}
C++ (Qt)class PotokThread : public QThread{ Q_OBJECT....public slots: void exitThread(); private: QMutex m_stopMutex; bool m_stopped;}; PotokThread::~PotokThread(){ exitThread();}; void PotokThread::exitThread(){ if (!isRunning()) return; m_stopMutex.lock(); m_stopped = true; m_stopMutex.unlock(); wait();} void PotokThread::run(){ m_stopMutex.lock(); m_stopped = false; m_stopMutex.unlock(); for(int i=100;i>=0 && !m_stopped;--i) { msleep(100); emit valueChanged(i); };};