mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
bug修复,包括添加数据转发实例时造成程序崩溃,及回传转发实例收到数据使能失效
This commit is contained in:
parent
c4c2f03b6e
commit
cf465bfa8c
@ -36,10 +36,12 @@ TcpTransmissionItemWidget::TcpTransmissionItemWidget(SAKDebugPage *debugPage, QW
|
|||||||
|
|
||||||
void TcpTransmissionItemWidget::write(QByteArray data)
|
void TcpTransmissionItemWidget::write(QByteArray data)
|
||||||
{
|
{
|
||||||
if (!tcpSocket->write(data)){
|
if (tcpSocket){
|
||||||
|
if (!tcpSocket->write(data)){
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
qDebug() << "发送取数据失败" << tcpSocket->errorString();
|
qDebug() << "发送取数据失败" << tcpSocket->errorString();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,14 +35,24 @@ UdpTransmissionItemWidget::UdpTransmissionItemWidget(SAKDebugPage *debugPage, QW
|
|||||||
SAKBase::instance()->initIpComboBox(addressComboBox);
|
SAKBase::instance()->initIpComboBox(addressComboBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UdpTransmissionItemWidget::~UdpTransmissionItemWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
if (udpSocket){
|
||||||
|
delete udpSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UdpTransmissionItemWidget::write(QByteArray data)
|
void UdpTransmissionItemWidget::write(QByteArray data)
|
||||||
{
|
{
|
||||||
QHostAddress targetAddress(targetAddressLineEdit->text());
|
if (udpSocket){
|
||||||
quint16 targetPort = static_cast<quint16>(targetPortLineEdit->text().toInt());
|
QHostAddress targetAddress(targetAddressLineEdit->text());
|
||||||
if (!udpSocket->writeDatagram(data, targetAddress, targetPort)){
|
quint16 targetPort = static_cast<quint16>(targetPortLineEdit->text().toInt());
|
||||||
|
if (!udpSocket->writeDatagram(data, targetAddress, targetPort)){
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
qDebug() << "发送数据失败" << udpSocket->errorString();
|
qDebug() << "发送数据失败" << udpSocket->errorString();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,13 +60,20 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
|||||||
{
|
{
|
||||||
auto closeDev = [&](QUdpSocket *dev){
|
auto closeDev = [&](QUdpSocket *dev){
|
||||||
disconnect(dev, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
disconnect(dev, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
||||||
dev->deleteLater();
|
delete dev;
|
||||||
dev = nullptr;
|
dev = nullptr;
|
||||||
this->setUiEnable(true);
|
this->setUiEnable(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto bindDev = [&](QHostAddress address, quint16 port){
|
auto bindDev = [&](QHostAddress address, quint16 port, bool customAddressAndPort){
|
||||||
if (udpSocket->bind(address, port)){
|
bool bindResult = false;
|
||||||
|
if (customAddressAndPort){
|
||||||
|
bindResult = udpSocket->bind(address, port);
|
||||||
|
}else{
|
||||||
|
bindResult = udpSocket->bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bindResult){
|
||||||
if (udpSocket->open(QUdpSocket::ReadWrite)){
|
if (udpSocket->open(QUdpSocket::ReadWrite)){
|
||||||
connect(udpSocket, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
connect(udpSocket, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
||||||
this->setUiEnable(false);
|
this->setUiEnable(false);
|
||||||
@ -64,7 +81,7 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit requestOutputMessage(udpSocket->errorString(), false);
|
emit requestOutputMessage(udpSocket->errorString(), false);
|
||||||
enableCheckBox->setChecked(false);
|
enableCheckBox->setChecked(false);
|
||||||
closeDev(udpSocket);
|
closeDev(udpSocket);
|
||||||
};
|
};
|
||||||
@ -72,9 +89,9 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
|||||||
if (enableCheckBox->isChecked()){
|
if (enableCheckBox->isChecked()){
|
||||||
udpSocket = new QUdpSocket;
|
udpSocket = new QUdpSocket;
|
||||||
if (customAddressCheckBox->isChecked()){
|
if (customAddressCheckBox->isChecked()){
|
||||||
bindDev(QHostAddress(addressComboBox->currentText()), static_cast<quint16>(portLineEdit->text().toInt()));
|
bindDev(QHostAddress(addressComboBox->currentText()), static_cast<quint16>(portLineEdit->text().toInt()), true);
|
||||||
}else{
|
}else{
|
||||||
bindDev(QHostAddress::Any, 0);
|
bindDev(QHostAddress(addressComboBox->currentText()), static_cast<quint16>(portLineEdit->text().toInt()), false);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
closeDev(udpSocket);
|
closeDev(udpSocket);
|
||||||
@ -83,6 +100,10 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
|||||||
|
|
||||||
void UdpTransmissionItemWidget::read()
|
void UdpTransmissionItemWidget::read()
|
||||||
{
|
{
|
||||||
|
if (!handleReceiveDataCheckBox->isChecked()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (udpSocket){
|
if (udpSocket){
|
||||||
while (udpSocket->hasPendingDatagrams()) {
|
while (udpSocket->hasPendingDatagrams()) {
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
|||||||
@ -33,6 +33,7 @@ class UdpTransmissionItemWidget:public BaseTransmissionItemWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UdpTransmissionItemWidget(SAKDebugPage *debugPage, QWidget *parent);
|
UdpTransmissionItemWidget(SAKDebugPage *debugPage, QWidget *parent);
|
||||||
|
~UdpTransmissionItemWidget();
|
||||||
|
|
||||||
virtual void write(QByteArray data);
|
virtual void write(QByteArray data);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -15,7 +15,11 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="6">
|
<item row="1" column="6">
|
||||||
<widget class="QLineEdit" name="targetPortLineEdit"/>
|
<widget class="QLineEdit" name="targetPortLineEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string>55555</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="3">
|
<item row="0" column="3">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
@ -25,10 +29,18 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="6">
|
<item row="0" column="6">
|
||||||
<widget class="QLineEdit" name="portLineEdit"/>
|
<widget class="QLineEdit" name="portLineEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string>44444</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="4">
|
<item row="1" column="4">
|
||||||
<widget class="QLineEdit" name="targetAddressLineEdit"/>
|
<widget class="QLineEdit" name="targetAddressLineEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string>127.0.0.1</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<widget class="QCheckBox" name="customAddressCheckBox">
|
<widget class="QCheckBox" name="customAddressCheckBox">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user