[Qt-interest] wget vs. QHttp download
Christian Dähn
daehn at asinteg.de
Fri Nov 5 15:09:07 CET 2010
Hi,
be careful using the QNAM - it's only working asynchronously and needs
an event queue - which can lead to very big problems and slow downs
(my experience runs from industrial apps build on Qt 2.x up to 4.6).
Here an example for a simple http download:
QString m_Hostname = "example.com";
QNetworkAccessManager manager(this);
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("http://" + m_HostName)));
if (!reply)
throw runtime_error("start(): invalid network reply pointer!");
// wait for finished network reply
QEventLoop loop;
QTimer timer;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start(THREAD_WAIT_TIME);
loop.exec();
QString html = reply->readAll();
if (reply->error() != QNetworkReply::NoError || html.length() < 1) {
qWarning("cannot connect to %s!", qPrintable(m_HostName));
}
I personally dislike the massive use and new dependencies to the main event loop -
till now I found no way to use QNAM in a blocking way - like the waitForXxx() calls of
QIODevice or QAbstractSocket.
@Trolls:
The new QNAM is a cool solutions if I only care about smart API design -
but in daily life it hast some serious pitfalls - like the performance problems
caused by many QNAM actions running in massive multithreading apps.
Did you ever thought about using QNAM in massive multithreading environments?
Flooding the main eventloop causes my apps to slow down - so I have to use
non-Qt classes - or to write my own QNAM implementation using the QAbstractSockets.
ciao,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101105/00f8cecc/attachment.html
More information about the Qt-interest-old
mailing list