Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ QByteArray和QString转换的问题_C++_Qt_Qt5 - Fatal编程技术网

C++ QByteArray和QString转换的问题

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

我有一个服务器和一个客户端,它们通过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;

    }
}
告诉我错误:

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);