binary file sending using qt4.3
dear friends,
i am using qt 4.3 for my tcp socket programming.
in my program i am able to send normal text file from one client application to server application.
But i am not able to send the binary file or exe file from client application to server application..Plz if any body is having the sample code plz share with me...
Re: binary file sending using qt4.3
Are you opening the file as TEXT file ??
can we see the code ?
Re: binary file sending using qt4.3
Dear friend this is my sending side code for text file transfer..
Code:
void client::sendFile()
{
QMessageBox::information(this, tr
("File"),tr
("File cannot be opened."));
out << (quint16)0;
while (!file.atEnd())
{
out<<om;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
tcpclient->write(block);
}
file.close();
}
Then this is my receive side code for text file
Code:
void server::readClient()
{
QFile file("new_file.txt");
QMessageBox::information(this, tr
("File"),tr
("File cannot be opened."));
forever
{
if (blockSize == 0)
{
if (clientConnection->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (clientConnection->bytesAvailable() < blockSize)
return;
in>>strData;
txtStrmForFile<<strData;
strData="";
blockSize=0;
}
file.close();
}
This works fine as far as new.txt is a text file..but for other files e.g. for any other file this is not working..plz anybody can modify this code and suggest what to be done ..This code is in Qt4.3.3.
bye
Re: binary file sending using qt4.3
I suppose the problem is here:
Using readLine doesn't make sense with binary files. And there is no need to convert binary data to unicode.