问题:
tcp连接总是秒成功后断连
debug会出现下面这些
onecore\net\netprofiles\service\src\nsp\dll\namespaceserviceprovider.cpp(550)\nlansp_c.dll!00007FFDA2A1D93D: (caller: 00007FFDD8BEACF6) LogHr(1) tid(336c) 8007277C ´Ë·þÎñ²>>´æÔÚ¡£ÔÚÖ¸¶¨µÄÃüÃû¿Õ¼äÖÐÕÒ²>>Õâ¸ö·þÎñ¡£
onecore\net\netprofiles\service\src\nsp\dll\namespaceserviceprovider.cpp(1265)\nlansp_c.dll!00007FFDA2A1CD90: (caller: 00007FFDD8BF15A8) LogHr(2) tid(336c) FFFFFFFF
窗口源码:
cpp
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QWidget(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
sock = new QTcpSocket(this);//Login的成员变量QTcpSocket*
sock->abort();
//与服务器连接成功会发出信号
connect(sock,&QTcpSocket::connected,[this]()
{
chatwindow = new ChatWindow(sock,this);
chatwindow->set_user_name(ui->usernameTextEdit->text());
chatwindow->show();
this->hide();
QMessageBox::information(this,"连接提示","连接成功!");
});
connect(sock,&QTcpSocket::disconnected,[this](){
QMessageBox::warning(this,"连接提示","异常!连接断开!");
});
}
Login::~Login()
{
delete ui;
}
//连接按钮
void Login::on_pushButton_clicked()
{
QString name_string = ui->usernameTextEdit->text();
if(name_string.count() ==0)
{
QMessageBox::information(this,"输入提示","请输入用户名!");
return;
}
QString ip_string = ui->ipTextEdit->text();
QString port_string = ui->portTextEdit->text();
qDebug() << ip_string;
qDebug() << port_string;
sock->abort();
sock->connectToHost(QHostAddress(ip_string),port_string.toInt());
}
debug内容
//Chatwindow的源码
cpp
#include "chatwindow.h"
#include "ui_chatwindow.h"
ChatWindow::ChatWindow(QTcpSocket* sock_ref,QWidget *parent) :
QWidget(parent),
ui(new Ui::ChatWindow)
{
ui->setupUi(this);
this->sock = sock_ref;//ChatWindow的成员变量QTcpSocket*
qDebug()<< "ChatWindow start";
}
ChatWindow::~ChatWindow()
{
delete ui;
qDebug()<< "ChatWindow end";
}
void ChatWindow::set_user_name(QString user_name)
{
msg["user_name"] = user_name;
qDebug()<<"ChatWindow set user name :" << msg["user_name"];
}
void ChatWindow::on_sendPushButton_clicked()
{
}