Reputation: 571
I've got a server and a client and they're connected by TCP (QTcpSocket and QTcpServer). data is sent using 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 prints the text entered in client in server's console. i want to convert buffer to QString. (or i want to send it to qml file). so when i try :
QString receivedText = QTextCodec::codecForMib(1015)->toUnicode(buffer);
and give me the error :
no matching function for call to 'QTextCodec::toUnicode(QByteArray*&)'
receivedText = QTextCodec::codecForMib(1015)->toUnicode(buffer);
^
when using fromAscii or fromStringC it says it's not a member of QString.
what should i do?
Upvotes: 0
Views: 442
Reputation: 244252
According to the documentation:
QString QTextCodec::toUnicode(const QByteArray &a) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString.
From the above, it follows that the reference is needed and not the pointer. In your case you should change it to:
QString receivedText = QTextCodec::codecForMib(1015)->toUnicode(*buffer);
Upvotes: 2