My application sent object to the server via QTcpSocket
.
Client:
void client::sendFile(QString path)
{
QFile toSend(path);
QByteArray rawFile;
rawFile = toSend.readAll();
QDataStream out(cl);
out >> rawFile;
}
Server:
void server::handleClient()
{
QTcpSocket *curCl = srv->nextPendingConnection();
QByteArray z;
QDataStream in(curCl);
in >> z;
QFile qwe("test.dat");
qwe.write(z);
qwe.close();
}
The problem is that nothing happens, but debug console told me:
QIODevice::write: device not open
QIODevice::read: device not open
... but the QDataStream
object doesn't allow me to set open mode up! :(
Whats wrong?
QFile
+QFile.write
(orQFile.read
) requiresQFile.open
, see example:Write:
or
Read: