QT调试代码中出现
Internal error: pc 0xa0520000 in read in psymtab, but not in symtab.
请问下这是问题,怎么解决?对程序有影响吗?
下面是我的代码
#include "socketwidget.h"
#include
#include
#include
#include
#include
#include
#include
SocketWidget::SocketWidget(QWidget *parent)
: QWidget(parent)
{
send_btn = new QPushButton(this);
send_btn->setText("send");
send_btn->setGeometry(9,268,78,23);
close_btn = new QPushButton(this);
close_btn->setText("close");
close_btn->setGeometry(316,268,75,23);
connect_btn = new QPushButton(this);
connect_btn->setText("connect");
connect_btn->setGeometry(316,20,75,23);
connect(send_btn,&QPushButton::clicked,this,&SocketWidget::on_buttonSend_clicked);
connect(close_btn,&QPushButton::clicked,this,&SocketWidget::on_buttonClose_clicked);
connect(connect_btn,&QPushButton::clicked,this,&SocketWidget::on_buttonConnect_clicked);
send_btn->setEnabled(false);
close_btn->setEnabled(false);
label1 = new QLabel(this);
label1->setText("服务器IP:");
label1->setGeometry(9,9,72,20);
label2 = new QLabel(this);
label2->setText("服务器端口:");
label2->setGeometry(9,35,72,20);
lineEditIP = new QLineEdit(this);
lineEditIP->setText("127.0.0.1");
lineEditIP->setGeometry(87,9,223,20);
lineEditPort = new QLineEdit(this);
lineEditPort->setText("8888");
lineEditPort->setGeometry(87,35,223,20);
textEditRead = new QTextEdit(this);
textEditRead->setReadOnly(true);
textEditRead->setGeometry(9,61,382,97);
textEditWrite = new QTextEdit(this);
textEditWrite->setGeometry(9,164,382,98);
tcpSocket =NULL;
//分配空间制定父对象
tcpSocket = new QTcpSocket(this);
setWindowTitle("客户端");
connect(tcpSocket,&QTcpSocket::connected,
[=]()
{
textEditRead->setText("成功和服务器连接");
send_btn->setEnabled(true);
close_btn->setEnabled(true);
connect_btn->setEnabled(false);
}
);
connect(tcpSocket,&QTcpSocket::readyRead,this,&SocketWidget::onSocketReadyRead);
connect(tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
this, &SocketWidget::displayError);
}
SocketWidget::~SocketWidget()
{
}
void SocketWidget::onSocketReadyRead()
{
if(tcpSocket->bytesAvailable() <= 0)
{
return;
}
qint64 totalBytes = 0;
m_buffer = NULL;
//从缓存区去除数据,但是不确定取出来的字节数;
QByteArray buffer= tcpSocket->readAll();
m_buffer.append(buffer);
unsigned int totalLen = m_buffer.size();
textEditRead->append(buffer);
//这边确实需要利用长度做while循环,因为有可能一下子读取到两条以上的完整记录,就需要进行循环处理了;
//超过一条完整小于第二条完整记录时,如果已经达到包头长度就先把包头保存下来,整个过程循环往复
while (totalLen)
{
//与QDataStream绑定,方便操作
QDataStream packet(m_buffer);
packet.setVersion(QDataStream::Qt_5_10);
//不够包头长度的不处理,结束while循环
unsigned int MINSIZE = sizeof(qint64)*2;
if(totalLen < MINSIZE)
{
//textEditRead->append(buffer);
break;
}
//将包头读入了进来按照定义的协议,先读命令长度,再读命令的类型;
packet >> totalBytes >>serverCmd;
//缓存中的内容长度没有达到命令的长度,那就先结束,等足够了再来解析
if(totalLen<totalBytes)
break;
//足够长了就开始解析
// QDir dir(sysFilePath); //系统文件目录
// if(!dir.exists())
// dir.mkdir(sysFilePath);
switch (serverCmd)
{
case QString_recv:
{
qDebug()<<"开始接收字符串...";
QByteArray datas = m_buffer.mid(MINSIZE,totalBytes-MINSIZE);
QString strInfo;//数据包中的message
strInfo.prepend(datas);
qDebug() <<strInfo;//输出接收到的QString
}
break;
default:
//qint64 nbytes = tcpSocket->bytesAvailable();
//textEditRead->append(buffer);
break;
}
//缓存多余的数据
buffer = m_buffer.right(totalLen - totalBytes); //截取下一个数据包的数据,留作下次读取
totalLen = buffer.size();
//更新多余的数据
m_buffer = buffer;
}
/* while (tcpSocket->bytesAvailable() > 0)
{
qint64 nbytes = tcpSocket->bytesAvailable();
QByteArray array = tcpSocket->read(nbytes);
textEditRead->append(array);
}*/
}
void SocketWidget::on_buttonConnect_clicked()
{
QHostAddress localIP = QHostAddress("127.0.0.1");
//获取服务器ip和端口
QString ip = lineEditIP->text();
qint16 port = lineEditPort->text().toInt();
//tcpSocket->abort();
if(tcpSocket->bind(localIP,42055) )
{
qDebug() << "1 localHost:" << localIP.toString();
qDebug() << "2 localPort:" << tcpSocket->localPort();
}
tcpSocket->abort();
//主动和服务器建立连接
tcpSocket->connectToHost(ip, port);
if(tcpSocket->waitForConnected(1000) )
{
send_btn->setEnabled(true);
close_btn->setEnabled(true);
connect_btn->setEnabled(false);
}
else
{
QMessageBox::information(this, tr(" Client"),
tr("连接失败,请检查后重试"));
}
}
void SocketWidget::on_buttonSend_clicked()
{
//获取编辑框内容
QString str = textEditWrite->toPlainText();
//发送数据
tcpSocket->write(str.toUtf8().data() );
if(tcpSocket->waitForBytesWritten(1000) )
{
textEditWrite->clear();
}
else
{
QMessageBox::information(this, tr(" Client"),
tr("内容为空,输入后从新发送"));
}
}
void SocketWidget::displayError(QAbstractSocket::SocketError socketError)
{
switch (socketError) {
case QAbstractSocket::RemoteHostClosedError:
connect_btn->setEnabled(true);
send_btn->setEnabled(false);
close_btn->setEnabled(false);
QMessageBox::information(this, tr(" Client"),
tr("The host was disconnect. Please check and "
"request again."));
textEditRead->append("服务器已断开连接");
break;
case QAbstractSocket::HostNotFoundError:
QMessageBox::information(this, tr(" Client"),
tr("The host was not found. Please check the "
"host name and port settings."));
break;
case QAbstractSocket::ConnectionRefusedError:
QMessageBox::information(this, tr(" Client"),
tr("The connection was refused by the peer. "
"Make sure the server is running, "
"and check that the host name and port "
"settings are correct."));
break;
default:
QMessageBox::information(this, tr(" Client"),
tr("The following error occurred: %1.")
.arg(tcpSocket->errorString()));
}
}
void SocketWidget::on_buttonClose_clicked()
{
//主动和对方断开连接
tcpSocket->disconnectFromHost();
if(tcpSocket->state() == QAbstractSocket::UnconnectedState
|| tcpSocket->waitForDisconnected(1000) )
{
tcpSocket->close();
connect_btn->setEnabled(true);
send_btn->setEnabled(false);
close_btn->setEnabled(false);
textEditRead->append("已断开连接");
}
else
{
QMessageBox::information(this, tr(" Client"),
tr("断开连接失败,请检查后重试"));
}
}