exit(); wait();
while (thread->isRunning()){ QCoreApplication::processEvents(QEventLoop::AllEvents);}
#ifndef THREAD_H#define THREAD_H#include <QThread>class Thread : public QThread{ Q_OBJECTpublic: Thread( QObject *parent ); void run();public slots: void connectReady(); void connectLost();signals: void alive();};#endif // THREAD_H
#include "thread.h"#include <QTimer>Thread::Thread( QObject *parent ) : QThread( parent ){}void Thread::run(){ QTimer tm; tm.setSingleShot( false ); connect( &tm, SIGNAL( timeout() ), this, SIGNAL( alive() ) ); tm.start( 200 ); exec();}void Thread::connectReady(){ start();}void Thread::connectLost(){ exit(); wait();}
void jProtocol::onDisconnect(ConnectionError e){ qDebug() << "exit"; TreeModelItem item; item.m_protocol_name = "Jabber"; item.m_account_name = m_account_name; item.m_item_type = 2; if(e != ConnUserDisconnected && e != ConnNotConnected) { QString error_tr; switch(e) { ---тут ошибки и установка error_tr--- } emit systemNotification(m_account_name,error_tr); } m_jabber_account->getPluginSystem().setAccountIsOnline(item, false); m_jabber_roster->setOffline(); emit setRealStatus(Presence::Unavailable); ---Тут поток должен завершаться---}