PDA

View Full Version : HTTP pause download in QTCreator



nhs_0702
16th April 2010, 10:36
i want create program download have pause download,can you help me ?

wysota
16th April 2010, 10:47
http://doc.trolltech.com/qq/qq17-ratecontrol.html

AlekseyK
28th November 2010, 15:46
This example does not work since Qt 4.2: http://www.qtcentre.org/threads/10208-How-to-limit-download-speed-with-QHttp?p=167314#post167314

Have You tried it at least once? Does it work for You???

wysota
28th November 2010, 16:28
http://labs.qt.nokia.com/2006/09/11/behavioral-changes-in-qiodevice-in-qt-42/

squidge
28th November 2010, 17:08
and the documentation explains why and how to still make it do what you want: http://labs.qt.nokia.com/2006/09/11/behavioral-changes-in-qiodevice-in-qt-42/

AlekseyK
28th November 2010, 19:56
Yes, explains. But it was not enough for me. I took Qt Torrent example, removed all torrent relative code from PeerWireClient (renamed it to KTcpSocket) as I need only tcp socket with rate control. But the program does not work at all. May I ask You to look at the code, please, where is the cause. Code attached. RateController class works just fine, checked, think the problem is in modified PeerWireClient class (my class name is KTcpSocket).

AlekseyK
28th November 2010, 20:10
I Saw this: http://www.qtcentre.org/threads/10208-How-to-limit-download-speed-with-QHttp?p=167314#post167314

I took Qt Torrent example, removed all torrent relative code from PeerWireClient (renamed it to KTcpSocket) as I need only tcp socket with rate control. But the program does not work at all. May I ask You to look at the code, please, where is the cause. Code attached. RateController class works just fine, checked, think the problem is in modified PeerWireClient class (my class name is KTcpSocket).

wysota
28th November 2010, 20:32
How does "does not work at all" manifest itself?

AlekseyK
28th November 2010, 20:51
http://doc.trolltech.com/qq/qq17-ratecontrol.html example after fixes gets web page partially and outputs it to stdout. Same program but with PeerWireClient (without or with Torrent code) as socket class does nothing. No output at all.

squidge
28th November 2010, 22:57
If one class works just fine and another class does not, why not just use the class which works fine?

How does PeerWireClient work? Is it similar to rate control?

(Surely you understand how the class works before trying to use it?)

AlekseyK
28th November 2010, 23:07
I tried to take PeerWireClient without modifications: does not work also as regular QTcpSocket.


#include "ratecontroller.h"
#include "peerwireclient.h"

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>

class Foo : public QObject
{
Q_OBJECT
public slots:
void showData()
{
PeerWireClient *socket = (RcTcpSocket *)sender();
//QTcpSocket *socket = (QTcpSocket *)sender();
while (socket->canReadLine())
qDebug() << socket->readLine();
}

void onExit()
{
PeerWireClient *socket = (PeerWireClient *)sender();
qDebug() << "bytesAvailable: " << socket->bytesAvailable();
qDebug() << "socketBytesAvailable: " << socket->socketBytesAvailable();
qDebug() << "canReadLine: " << socket->canReadLine();
qDebug() << "socketCanReadLine: " << socket->QTcpSocket::canReadLine();
}
};

int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

RateController controller;
controller.setUploadLimit(100);
controller.setDownloadLimit(100);

PeerWireClient socket;
controller.addSocket(&PeerWireClient);
socket.connectToHost("qt.nokia.com", 80);

Foo foo;

QObject::connect(&socket, SIGNAL(readyRead()), &foo, SLOT(showData()));
QObject::connect(&socket, SIGNAL(readChannelFinished()), &foo, SLOT(onExit()));
//QObject::connect(&socket, SIGNAL(readChannelFinished()), &app, SLOT(exit()));

socket.write("GET / HTTP/1.0\r\n\r\n");
return app.exec();
}

#include "main.moc"

Have You ever tried to test or use either qq17-ratecontrol.html example or Torrent example? Or ever implemented QTcpSocket with speed limitation feature?

wysota
28th November 2010, 23:29
Sorry but the code you posted will not even compile.

AlekseyK
29th November 2010, 14:24
I've found something: in Qt torrent example readLine functions was missed cause they were unnecessary for torrent. I added them to my KTcpSocket class definition (former PeerWireClient class):



QByteArray readLine (qint64 maxSize = 0) { return socket.readLine(maxSize); }
qint64 readLine(char *data, qint64 maxSize) { return socket.readLine(data, maxSize); }

And this is naturally and understandable because real data is sent QTcpSocket socket class member for which KTcpSocket acts as proxy. Now KTcpSocket instance receives data correctly but there is no traffic throttling, ;) because socket's readyRead() signlal connected to readyRead() proxy signal. It is like endless cycle. :D Do not know what to do now??? :) However output traffic throttling should work (do not know how to test it for now).

wysota, sorry for the code: probably put wrong archive here. Re-attached modified version (should compile).