QHttp RequestStarted does not even begin!
I set up my project, using QT += network
It's a static app and I included QtNetwork.
I made sure all the connections are connected... no problems there...
Code:
connect(http, SIGNAL(stateChanged(int)), this, SLOT(DisplayProgress(int)));
connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(requestStarted (int)), this, SLOT(httpRequestStarted(int)));
connect(http, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
Neither get(), nor post() has any problem executing. But after that everything seems to go silent.
Like as if the signals aren't working at all.
I put logs everywhere, and not a single connected signal is being emitted. requestStarted doesn't even begin.
I made sure to follow the example in QHttp. I simply put up a GET for a PHP page online. I am online, firewall is off and everything (though it is vista).
Code:
void httpRequestStarted(int id){
if(id == httpPostId){
Log2("Started");
} else if (id == httpGetId){
Log2("Started");
}
Log2("Req Started");
}
But nothing is getting logged.
Apparently, either QtNetwork isn't working, or neither get nor post activates httpRequestStarted.
I declared http as a QHttp(this) (this being a QObject class).
The logs just stop here and here:
Code:
void cConnect
::PostRead(QString data,
const QString
& siteurl,
int encrypt
){ //data = Encrypt(data);
httpRequestAborted = false;
httpPostId
= http
->post
(QUrl::toPercentEncoding(siteurl
), data.
toAscii());
}
This is for GET:
Code:
httpRequestAborted = false;
httpGetId
= http
->get
(QUrl::toPercentEncoding(Url
),
file);
Log2("CC::Downloading File");
How can this be? I never declared a "Host" and I never get the signal for requestStart().
Re: QHttp RequestStarted does not even begin!
Are you running the event loop (for instance by calling QApplication::exec())?
Re: QHttp RequestStarted does not even begin!
In another file, I am running exec(), it's not a threaded app.
Also, I recently tried to see if simply setHost() is working, but even that doesn't work. No signals emitted.
However, signals are emitted in another test app i compiled.. So weird.
Also, when I immediately (not in any slot or signal), right after setHost, I typed:
http->errorString().toLocal8Bit().constData() for my log.
It says "Unknown Error". Shouldn't it say "No Error"?
At some point I did receive signals, but then they disappeared, I can't reproduce them.
Re: QHttp RequestStarted does not even begin!
Can you prepare a minimal compilable example reproducing the problem?
Re: QHttp RequestStarted does not even begin!
Well, when I opened the HTTP example inside my Qt directory, it wasn't working, some sort of missing dynamic link in qtnetwork.
Then, I took the code, put it in a different folder, compiled it myself, to see if my static compiled Qt works properly. And the HTTP downloader works nicely.
So my environment should be fine.
I even tried compiling http.exe as static, it worked fine too. It means that it must be something in my code maybe.
But I did everything, I triple checked all the codes, compared it with other http programs including your own. What are possible causes of signals not being emitted?
Re: QHttp RequestStarted does not even begin!
Re: QHttp RequestStarted does not even begin!
Ok I figured it out.
You were right the first time wysota.
See I do have an application running as app.exec(), but what I later meditated and figured out was, that if you have a program that works and then a function calls a new class (which does the HTTP work), then that new class returns, and then the function ends. And my problem was, I declared the class as a local object and it was on the local stack, so as soon as that function returned as well, the HTTP class never got a chance to run long enough to create signals etc... As soon as I changed the local object to a pointer object that runs throughout the main class, it worked perfectly.
Thanks.