void CClientComWorker::slotError(QAbstractSocket::SocketError nSocketError) { QString strSocketError; QString strErrorString; QString strSocketState; strSocketError = CTcpSocketHelper::getStringValue(nSocketError); strErrorString = m_pSocketHandle->errorString(); strSocketState = CTcpSocketHelper::getStringValue(m_pSocketHandle->state()); if (QAbstractSocket::SocketTimeoutError == nSocketError) { //do nothing } else if (QAbstractSocket::ConnectionRefusedError == nSocketError || QAbstractSocket::RemoteHostClosedError == nSocketError || QAbstractSocket::HostNotFoundError == nSocketError ) { MYLOG4CPP_DEBUG<<" "<<"m_strID="<<m_pSocketInfo->m_strID <<" "<<"class:"<<" "<<"CClientComWorker" <<" "<<"fun:"<<" "<<"slotError" <<" "<<"emit signalDisconnected()" <<" "<<"param:"<<" "<<"m_nHandle="<<m_nHandle; emit signalDisconnected(m_nHandle); } else { MYLOG4CPP_DEBUG<<"m_strID="<<m_pSocketInfo->m_strID <<" "<<"strSocketError="<<strSocketError <<" "<<"strErrorString="<<strErrorString <<" "<<"strSocketState="<<strSocketState; } }
void CClientComWorker::run() { MYLOG4CPP_DEBUG<<"CClientComWorker::run() begin"; { QMutexLocker lock(&m_mutex_SocketW); m_pSocketHandle = new QTcpSocket(); m_pSocketInfo = new CSocketInfo(); } // QObject::connect(m_pSocketHandle, SIGNAL(connected()), this, SLOT(slotConnected()), Qt::AutoConnection); QObject::connect(m_pSocketHandle, SIGNAL(disconnected()), this, SLOT(slotDisconnected()), Qt::AutoConnection); QObject::connect(m_pSocketHandle, SIGNAL(readyRead()), this, SLOT(slotReadyRead()), Qt::AutoConnection);//Qt::AutoConnection Qt::BlockingQueuedConnection QObject::connect(m_pSocketHandle, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)), Qt::AutoConnection); m_WorkerState = WORK_STATE_BEGIN; m_WorkerState = WORK_STATE_WORKING; //slotConnectToServer(); MYLOG4CPP_DEBUG<<" "<<"m_strID="<<m_pSocketInfo->m_strID <<" "<<"class:"<<" "<<"CClientComWorker" <<" "<<"fun:"<<" "<<"run" <<" "<<"emit signalDisconnected()" <<" "<<"param:"<<" "<<"m_nHandle="<<m_nHandle; emit signalDisconnected(m_nHandle); MYLOG4CPP_DEBUG<<"CClientComWorker::run() exec() begin"; //QThread::exec() waits until QThread::exit() called exec(); MYLOG4CPP_DEBUG<<"CClientComWorker::run() exec() end"; // QObject::disconnect(m_pSocketHandle, SIGNAL(connected()), this, SLOT(slotConnected())); QObject::disconnect(m_pSocketHandle, SIGNAL(disconnected()), this, SLOT(slotDisconnected())); QObject::disconnect(m_pSocketHandle, SIGNAL(readyRead()), this, SLOT(slotReadyRead())); QObject::disconnect(m_pSocketHandle, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError))); { QMutexLocker lock(&m_mutex_SocketW); if (NULL != m_pSocketHandle) { //m_pSocketHandle->waitForDisconnected(); m_pSocketHandle->close(); delete m_pSocketHandle; m_pSocketHandle = NULL; } if (NULL != m_pSocketInfo) { delete m_pSocketInfo; m_pSocketInfo = NULL; } } m_WorkerState = WORK_STATE_END; MYLOG4CPP_DEBUG<<"CClientComWorker::run() end"; }
void Server::incomingConnection(qintptr handle) { TcpClientSocket *client = new TcpClientSocket(this); client->setSocketDescriptor(handle); connect(client, SIGNAL(signalMsg(qintptr)), this, SLOT(slotReadMsg(qintptr))); connect(client, SIGNAL(signalDisconnected(qintptr, QString)), this, SLOT(slotDisconnected(qintptr, QString))); clientList.insert(handle, client); }
void Server::slotDisconnected(qintptr sockd, QString szClientName) { QMap<qintptr, TcpClientSocket*>::iterator clientIt; clientIt = clientList.find(sockd); if (clientIt != clientList.end()) { qDebug() << "void Server::slotDisconnected() - sockd=" << sockd << ", clientName=" << szClientName << " disconnected"; clientList.erase(clientIt); } emit signalDisconnected(sockd, szClientName); }
squeeze::squeeze() : KXmlGuiWindow( ), m_view(new squeezeView(this)), m_printer(0) { setObjectName(QLatin1String("squeeze")); // accept dnd setAcceptDrops(false); // tell the KXmlGuiWindow that this is indeed the main widget setCentralWidget(m_view); // then, setup our actions setupActions(); //Add some widgets to status bar led = new KLed; led->off(); statusBar()->addWidget(led); //FIXME: Que cuando se escriba algo en la barra de status, quede el LED ahi tambien. // add a status bar statusBar()->show(); // Add typical actions and save size/toolbars/statusbar setupGUI(); disableUI(); // allow the view to change the statusbar and caption connect(m_view, SIGNAL(signalChangeStatusbar(const QString&)), this, SLOT(changeStatusbar(const QString&))); connect(m_view, SIGNAL(signalChangeCaption(const QString&)), this, SLOT(changeCaption(const QString&))); connect(m_view, SIGNAL(signalDisconnected()), this, SLOT(setDisconnected())); connect(m_view, SIGNAL(signalConnected()), this, SLOT(setConnected())); connect(m_view, SIGNAL(signalShowPrefs()), SLOT(optionsPreferences()) ); connect(m_view, SIGNAL(signalSalir() ), SLOT(salir() )); connect(m_view, SIGNAL(signalShowDbConfig()), this, SLOT(showDBConfigDialog())); connect(m_view, SIGNAL(signalAdminLoggedOn()), this, SLOT(enableUI())); connect(m_view, SIGNAL(signalAdminLoggedOff()), this, SLOT(disableUI())); connect(m_view, SIGNAL(signalSupervisorLoggedOn()), this, SLOT(enableUI())); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(fixGeom())); timer->setInterval(5000); timer->start(); loadStyle(); }
void Server::incomingConnection(qintptr socketDescriptor) { Client *client = new Client(socketDescriptor); clients->push_back(client); QObject::connect(client,SIGNAL(sendMessageToAll(QString)),this,SLOT(sendMessageToAll(QString))); QObject::connect(client,SIGNAL(showDialog(QString)),this,SLOT(onShowDialog(QString))); QObject::connect(client,SIGNAL(signalDisconnected(QString)),this,SLOT(onClientDisconnected(QString))); QObject::connect(client,SIGNAL(signalConnected(QString)),this,SLOT(onClientConnected(QString))); QObject::connect(client,SIGNAL(saveHistory(QString)),this,SLOT(onSaveHistory(QString))); QObject::connect(client,SIGNAL(getHistory()),this,SLOT(onGetHistory(Client*))); onGetHistory(client); }
void CClientComWorker::slotDisconnected() { MYLOG4CPP_DEBUG<<" "<<"m_strID="<<m_pSocketInfo->m_strID <<" "<<"class:"<<" "<<"CClientComWorker" <<" "<<"slot:"<<" "<<"slotDisconnected"; MYLOG4CPP_DEBUG<<" "<<"m_strID="<<m_pSocketInfo->m_strID <<" "<<"class:"<<" "<<"CClientComWorker" <<" "<<"fun:"<<" "<<"slotDisconnected" <<" "<<"emit signalDisconnected()" <<" "<<"param:"<<" "<<"m_nHandle="<<m_nHandle; emit signalDisconnected(m_nHandle); }
void CDistributeTaskWorker::run() { MYLOG4CPP_DEBUG<<"CStockTcpClientActor::run()"; m_pComWorker = new CClientComWorker(m_strServerIP, m_nServerPort, this); QObject::connect(m_pComWorker, SIGNAL(signalDisconnected()), this, SLOT(slotDisconnected()), Qt::AutoConnection); QObject::connect(m_pComWorker, SIGNAL(signalConnected()), this, SLOT(slotConnected()), Qt::AutoConnection); QObject::connect(this, SIGNAL(signalConnectToServer()), m_pComWorker, SLOT(slotConnectToServer()), Qt::AutoConnection); // m_pMessageManager = new CMessageManager(this); QObject::connect(m_pComWorker, SIGNAL(signalProcessMessage(QByteArray*)), m_pMessageManager, SLOT(slotProcessMessage(QByteArray*)), Qt::AutoConnection); QObject::connect(m_pMessageManager, SIGNAL(signalWriteMessage(QByteArray*)), m_pComWorker, SLOT(slotWriteMessage(QByteArray*)), Qt::AutoConnection); m_pComWorker->start(); m_WorkerState = WORK_STATE_BEGIN; m_WorkerState = WORK_STATE_WORKING; //QThread::exec() waits until QThread::exit() called exec(); if (NULL != m_pComWorker) { m_pComWorker->terminateAndWait(); delete m_pComWorker; m_pComWorker = NULL; } if (NULL != m_pMessageManager) { delete m_pMessageManager; m_pMessageManager = NULL; } m_WorkerState = WORK_STATE_END; }
void CConnectionListener::slotClientDisconnected(const CConnection* that) { qDebug() << "CConnectionListener::slotClientDisconnected"; emit signalDisconnected(that); }