Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ConnectThread.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "ConnectThread.h"
4#include <QLoggingCategory>
5
6static Q_LOGGING_CATEGORY(log, "Client.ConnectThread")
7
9 // Note that the parent object pointer cannot be set here.
10 // If set the parent, the object is also deleted
11 // when the parent object (CConnecterThread) is destroyed.
12 // Because it is deleted when it is finished.
13 : QThread(),
14 m_pConnecter(pConnect)
15{
16 bool check = false;
17 check = connect(this, SIGNAL(finished()),
18 this, SLOT(deleteLater()));
19 Q_ASSERT(check);
20}
21
22CConnectThread::~CConnectThread()
23{
24 qDebug(log) << "CConnectThread::~CConnectThread";
25}
26
38{
39 qDebug(log) << Q_FUNC_INFO << "start";
40
41 Q_ASSERT(m_pConnecter);
42 int nRet = 0;
43 CConnect* pConnect = m_pConnecter->InstanceConnect();
44 if(!pConnect)
45 {
46 qCritical(log) << "InstanceConnect fail";
47 emit m_pConnecter->sigDisconnect();
48 }
49
50 if(pConnect) {
51 nRet = pConnect->Connect();
52 if(nRet) {
53 pConnect->deleteLater();
54 pConnect = nullptr;
55 emit m_pConnecter->sigDisconnect();
56 }
57 }
58
59 exec();
60
61 if(pConnect) {
62 pConnect->Disconnect();
63 pConnect->deleteLater();
64 }
65
66 emit m_pConnecter->sigDisconnected();
67
68 qDebug(log) << Q_FUNC_INFO << "end";
69}
The class only is used by CConnecterThread.
virtual void run() override
Connect interface.
Definition Connect.h:45
virtual int Disconnect()
Disconnect.
Definition Connect.cpp:89
virtual int Connect()
Start connect.
Definition Connect.cpp:77
virtual CConnect * InstanceConnect()=0
New connect.
It starts a background thread by default.
void sigDisconnected()
Successful disconnection signal.
void sigDisconnect()
Notify the user to disconnect.