Hello everybody.
I know there were many topics with similar subjects, but I can't seem to find an answer for my problems so... here we are.
I want to create application, that would be able to download images from the internet. I know I could use QNetworkManager, but I would like to display image as soon as some part of it gets downloaded (like most browsers do), and QNetworkManager seems to display image after download is complete, so I want to try QTcpSocket. As a test, I am trying to download this image:
http://www.google.pl/images/srpr/nav_logo73.png
Here is some code:
socket.
connectToHost("www.google.pl",
80,
QIODevice::ReadWrite);
socket.waitForConnected();
socket.write("GET /images/srpr/nav_logo73.png");
socket.waitForReadyRead();
ba=socket.readAll();
MB.exec();
.
{
MB.
setText("Error! "+QString::number(socketError
));
MB.exec();
}
QMessageBox MB;
QTcpSocket socket;
connect(&socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError)));
socket.connectToHost("www.google.pl",80,QIODevice::ReadWrite);
socket.waitForConnected();
socket.write("GET /images/srpr/nav_logo73.png");
socket.waitForReadyRead();
QByteArray ba;
ba=socket.readAll();
MB.setText(QString(ba));
MB.exec();
.
void MainWindow::error(QAbstractSocket::SocketError socketError)
{
MB.setText("Error! "+QString::number(socketError));
MB.exec();
}
To copy to clipboard, switch view to plain text mode
Of course the above is meant to display any data that gets to the byteArray, but even this doesn't work, I got "SocketTimeoutError". What am I doing wrong?
Thanks in advance.
Bookmarks