void ChatCore::add_UI(QObject *ui_core) { this->ui_core=ui_core; QObject::connect(ui_core, SIGNAL(loginSignal(QString, QString, QString)), this, SLOT(tryconnect(QString, QString, QString))); QObject::connect(ui_core, SIGNAL(disconnectSignal()), this, SLOT(disconnect())); QObject::connect(ui_core, SIGNAL(sendMessSignal(QString, QString)), this, SLOT(send_mess(QString, QString))); }
TransmitThread::TransmitThread(QObject *parent) : QThread(parent), m_pTcpSocket(NULL), m_hHostIp(QHostAddress("127.0.0.1")), m_nHostPort(6010), m_bConnect(false), m_bDisconnect(false), m_bRunning(false), m_bStopped(false) { connect(this, SIGNAL(recvSignal(const QByteArray &)), parent, SLOT(switchStation(const QByteArray &))); connect(this, SIGNAL(connectSignal()), parent, SLOT(connectRequest())); connect(this, SIGNAL(disconnectSignal()), parent, SLOT(disconnectRequest())); }
void CtimerProperty::setSettingsToWidget(QString str) { int year,month,day,hour,min,sec; QDate date; QTime time; disconnectSignal(); settings.beginGroup(str); int type = settings.value("type").toInt(); if(type EQ TIMER_PROPERTY) { year = settings.value("dstYear").toInt(); month = settings.value("dstMon").toInt(); day = settings.value("dstDay").toInt(); date.setDate(year, month, day); dstDateTimeEdit->setDate(date); hour = settings.value("dstHour").toInt(); min = settings.value("dstMin").toInt(); sec = settings.value("dstSec").toInt(); time.setHMS(hour, min, sec, 0); dstDateTimeEdit->setTime(time); colorCombo->setCurrentIndex(settings.value("color").toInt()); styleCombo->setCurrentIndex(settings.value("style").toInt()); fontSizeCombo->setCurrentIndex(settings.value("size").toInt()); } else ASSERT_FAILED(); settings.endGroup(); if(type EQ TIMER_PROPERTY) { nameEdit->setSettingsToWidget(str); simpleTextEdit->setSettingsToWidget(str); smLineEdit->setSettingsToWidget(str); showModeEdit->setSettingsToWidget(str); borderEdit->setSettingsToWidget(str); } else ASSERT_FAILED(); connectSignal(); }
void TransmitThread::run() { m_bRunning = true; m_pTcpSocket = new QTcpSocket; initSocket(); forever { if(m_bStopped) { closeSocket(); //mutex.lock(); m_recvQueue.clear(); m_sendQueue.clear(); //mutex.unlock(); break; } if(m_pTcpSocket->state() == QAbstractSocket::ConnectedState) { m_pTcpSocket->waitForDisconnected(10); m_pTcpSocket->waitForReadyRead(10); if(m_bDisconnect) { closeSocket(); m_bDisconnect = false; } else { emit disconnectSignal(); } } else { if(m_bConnect) { m_pTcpSocket->connectToHost(m_hHostIp, m_nHostPort); m_pTcpSocket->waitForConnected(1000); m_bConnect = false; } else { emit connectSignal(); } } //mutex.lock(); if (!m_recvQueue.isEmpty()) { emit recvSignal(m_recvQueue.dequeue()); } if (!m_sendQueue.isEmpty()) { send(m_sendQueue.dequeue()); } if (m_recvQueue.isEmpty() && m_sendQueue.isEmpty()) { msleep(50); } //mutex.unlock(); } if (m_pTcpSocket != NULL) { delete m_pTcpSocket, m_pTcpSocket = NULL; } this->exec(); }