【发布时间】:2017-12-12 20:50:01
【问题描述】:
我有一个服务器和一个客户端,它们通过 TCP(QTcpSocket 和 QTcpServer)连接。使用 QByteArray 发送数据。
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;
}
}
last Line 在服务器控制台打印客户端输入的文本。我想将缓冲区转换为 QString。 (或者我想将它发送到 qml 文件)。所以当我尝试时:
QString receivedText = QTextCodec::codecForMib(1015)->toUnicode(buffer);
然后告诉我错误:
no matching function for call to 'QTextCodec::toUnicode(QByteArray*&)'
receivedText = QTextCodec::codecForMib(1015)->toUnicode(buffer);
^
当使用 fromAscii 或 fromStringC 时,它表示它不是 QString 的成员。
我该怎么办?
【问题讨论】: