改进代码

This commit is contained in:
feiyangqingyun
2021-11-07 14:51:52 +08:00
parent 39199724c2
commit ad847c7065
15 changed files with 73 additions and 21 deletions

View File

@@ -7,7 +7,11 @@ TcpClient1::TcpClient1(QObject *parent) : QTcpSocket(parent)
port = 6907;
deviceID = "SSJC00000001";
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#else
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#endif
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
}
@@ -142,10 +146,10 @@ bool TcpServer1::writeData(const QString &deviceID, const QString &data)
bool ok = false;
foreach (TcpClient1 *client, clients) {
if (client->getDeviceID() == deviceID) {
client->sendData(data);
ok = true;
client->sendData(data);
ok = true;
}
}
}
return ok;
}

View File

@@ -7,7 +7,11 @@ TcpClient2::TcpClient2(QObject *parent) : QTcpSocket(parent)
port = 6908;
deviceID = "SSJC00000001";
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
connect(this, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#else
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
#endif
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
}

View File

@@ -12,10 +12,9 @@ int main(int argc, char *argv[])
a.setFont(font);
//设置编码以及加载中文翻译文件
QUIHelper::setCode();
QUIHelper::setTranslator(":/qt_zh_CN.qm");
QUIHelper::setTranslator(":/widgets.qm");
QUIHelper::initRand();
QUIHelper::setCode();
QUIHelper::setTranslator();
AppConfig::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
AppConfig::readConfig();