C++ QByteArray和QString转换的问题
我有一个服务器和一个客户端,它们通过TCP QTcpSocket和QTcpServer连接。使用QByteArray发送数据C++ QByteArray和QString转换的问题,c++,qt,qt5,C++,Qt,Qt5,我有一个服务器和一个客户端,它们通过TCP QTcpSocket和QTcpServer连接。使用QByteArray发送数据 void Receive::newConnection() { while (server->hasPendingConnections()) { QTcpSocket *socket = server->nextPendingConnection(); connect(socket, SIGNAL(re
void Receive::newConnection()
{
while (server->hasPendingConnections())
{
QTcpSocket *socket = server->nextPendingConnection();
connect(socket, SIGNAL(readyRead()), SLOT(readyRead()));
connect(socket, SIGNAL(disconnected()), SLOT(disconnected()));
QByteArray *buffer = new QByteArray();
qint32 *s = new qint32(0);
buffers.insert(socket, buffer);
sizes.insert(socket, s);
qDebug()<<buffer;
}
}
告诉我错误:
no matching function for call to 'QTextCodec::toUnicode(QByteArray*&)'
receivedText = QTextCodec::codecForMib(1015)->toUnicode(buffer);
^
当使用fromscii或fromStringC时,表示它不是QString的成员
我该怎么办?根据:
QString QTextCodec::tounicodost QByteArray&a const
将此编解码器的编码转换为Unicode,并返回
产生一个QString
从上面可以看出,引用是必需的,而不是指针。在您的情况下,您应该将其更改为:
QString receivedText = QTextCodec::codecForMib(1015)->toUnicode(*buffer);
QString receivedText = QTextCodec::codecForMib(1015)->toUnicode(*buffer);