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,12 +36,14 @@ TcpTransmissionItemWidget::TcpTransmissionItemWidget(SAKDebugPage *debugPage, QW
|
||||
|
||||
void TcpTransmissionItemWidget::write(QByteArray data)
|
||||
{
|
||||
if (tcpSocket){
|
||||
if (!tcpSocket->write(data)){
|
||||
#ifdef QT_DEBUG
|
||||
qDebug() << "发送取数据失败" << tcpSocket->errorString();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TcpTransmissionItemWidget::on_enableCheckBox_clicked()
|
||||
{
|
||||
|
||||
@ -35,8 +35,17 @@ UdpTransmissionItemWidget::UdpTransmissionItemWidget(SAKDebugPage *debugPage, QW
|
||||
SAKBase::instance()->initIpComboBox(addressComboBox);
|
||||
}
|
||||
|
||||
UdpTransmissionItemWidget::~UdpTransmissionItemWidget()
|
||||
{
|
||||
delete ui;
|
||||
if (udpSocket){
|
||||
delete udpSocket;
|
||||
}
|
||||
}
|
||||
|
||||
void UdpTransmissionItemWidget::write(QByteArray data)
|
||||
{
|
||||
if (udpSocket){
|
||||
QHostAddress targetAddress(targetAddressLineEdit->text());
|
||||
quint16 targetPort = static_cast<quint16>(targetPortLineEdit->text().toInt());
|
||||
if (!udpSocket->writeDatagram(data, targetAddress, targetPort)){
|
||||
@ -45,18 +54,26 @@ void UdpTransmissionItemWidget::write(QByteArray data)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
||||
{
|
||||
auto closeDev = [&](QUdpSocket *dev){
|
||||
disconnect(dev, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
||||
dev->deleteLater();
|
||||
delete dev;
|
||||
dev = nullptr;
|
||||
this->setUiEnable(true);
|
||||
};
|
||||
|
||||
auto bindDev = [&](QHostAddress address, quint16 port){
|
||||
if (udpSocket->bind(address, port)){
|
||||
auto bindDev = [&](QHostAddress address, quint16 port, bool customAddressAndPort){
|
||||
bool bindResult = false;
|
||||
if (customAddressAndPort){
|
||||
bindResult = udpSocket->bind(address, port);
|
||||
}else{
|
||||
bindResult = udpSocket->bind();
|
||||
}
|
||||
|
||||
if (bindResult){
|
||||
if (udpSocket->open(QUdpSocket::ReadWrite)){
|
||||
connect(udpSocket, &QUdpSocket::readyRead, this, &UdpTransmissionItemWidget::read);
|
||||
this->setUiEnable(false);
|
||||
@ -72,9 +89,9 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
||||
if (enableCheckBox->isChecked()){
|
||||
udpSocket = new QUdpSocket;
|
||||
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{
|
||||
bindDev(QHostAddress::Any, 0);
|
||||
bindDev(QHostAddress(addressComboBox->currentText()), static_cast<quint16>(portLineEdit->text().toInt()), false);
|
||||
}
|
||||
}else{
|
||||
closeDev(udpSocket);
|
||||
@ -83,6 +100,10 @@ void UdpTransmissionItemWidget::on_enableCheckBox_clicked()
|
||||
|
||||
void UdpTransmissionItemWidget::read()
|
||||
{
|
||||
if (!handleReceiveDataCheckBox->isChecked()){
|
||||
return;
|
||||
}
|
||||
|
||||
if (udpSocket){
|
||||
while (udpSocket->hasPendingDatagrams()) {
|
||||
QByteArray data;
|
||||
|
||||
@ -33,6 +33,7 @@ class UdpTransmissionItemWidget:public BaseTransmissionItemWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
UdpTransmissionItemWidget(SAKDebugPage *debugPage, QWidget *parent);
|
||||
~UdpTransmissionItemWidget();
|
||||
|
||||
virtual void write(QByteArray data);
|
||||
private:
|
||||
|
||||
@ -15,7 +15,11 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<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 row="0" column="3">
|
||||
<widget class="QLabel" name="label">
|
||||
@ -25,10 +29,18 @@
|
||||
</widget>
|
||||
</item>
|
||||
<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 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 row="0" column="2">
|
||||
<widget class="QCheckBox" name="customAddressCheckBox">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user