关于QT编程TCP通讯 用write传输数据的问题
小生刚学QT,编了一个网络调试的基本小程序,但是在发送数据的时候用write写发送代码总是出现异常,停在了:qglobal.h中的inlineQFlagsoperator...
小生刚学QT,编了一个网络调试的基本小程序,但是在发送数据的时候用write写发送代码 总是出现异常,停在了:qglobal.h中的
inline QFlags operator&(Enum f) const { QFlags g; g.i = i & f; return g; }
中。
我的部分代码如下:
TCPTool::TCPTool(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
ui.setupUi(this);
connect(ui.listenPushButton,SIGNAL(clicked()),this,SLOT(creatListen()));
connect(ui.serverPushButton,SIGNAL(clicked()),this,SLOT(creatServer()));
}
void TCPTool::creatServer()
{
if (ui.ServerIP->text()==""||ui.ServerPort->text()=="")
{
QMessageBox::warning(this,tr("warning"),tr("Input port and IP number"),QMessageBox::Yes);
}
else
{
QTcpSocket *tcpSocket=new QTcpSocket(this);
int c=ui.ServerPort->text().toInt();
tcpSocket->abort();
tcpSocket->connectToHost(ui.ServerIP->text(),c);
connect(tcpSocket,SIGNAL(connected()),this,SLOT(connectServer()));
connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(connectError(QAbstractSocket::SocketError)));
}
}
void TCPTool::connectServer()
{
connect(ui.sendPushButton,SIGNAL(clicked()),this,SLOT(sendMessage()));
}
void TCPTool::sendMessage()
{
QString block=ui.serverTextEdit->toPlainText();
tcpSocket->write(qPrintable(block));
}
到tcpSocket->write(qPrintable(block))就出错了,小生真的不知道怎么办了,望高手指点一二,到底怎么回事腻 展开
inline QFlags operator&(Enum f) const { QFlags g; g.i = i & f; return g; }
中。
我的部分代码如下:
TCPTool::TCPTool(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
ui.setupUi(this);
connect(ui.listenPushButton,SIGNAL(clicked()),this,SLOT(creatListen()));
connect(ui.serverPushButton,SIGNAL(clicked()),this,SLOT(creatServer()));
}
void TCPTool::creatServer()
{
if (ui.ServerIP->text()==""||ui.ServerPort->text()=="")
{
QMessageBox::warning(this,tr("warning"),tr("Input port and IP number"),QMessageBox::Yes);
}
else
{
QTcpSocket *tcpSocket=new QTcpSocket(this);
int c=ui.ServerPort->text().toInt();
tcpSocket->abort();
tcpSocket->connectToHost(ui.ServerIP->text(),c);
connect(tcpSocket,SIGNAL(connected()),this,SLOT(connectServer()));
connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(connectError(QAbstractSocket::SocketError)));
}
}
void TCPTool::connectServer()
{
connect(ui.sendPushButton,SIGNAL(clicked()),this,SLOT(sendMessage()));
}
void TCPTool::sendMessage()
{
QString block=ui.serverTextEdit->toPlainText();
tcpSocket->write(qPrintable(block));
}
到tcpSocket->write(qPrintable(block))就出错了,小生真的不知道怎么办了,望高手指点一二,到底怎么回事腻 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询