PDA

View Full Version : QNetworkAccessManager->get freezes when called in DLL



Sajjmon
8th August 2012, 14:37
Hi. I have a dll where I want to do some networking, this dll is called from an C# application as an unmanaged DLL.
All initialization works fine but it freezes everytime the ->get() is supposed to run. I have this code:

.........
QUrl path(remotePath);
QNetworkRequest request(path);

currentFile.setFileName(localPath);
if(!currentFile.open(QIODevice::WriteOnly)){
doCallback("failed to open: " + localPath);
}
doCallback("before get: " + remotePath);
QNetworkReply* reply = this->manager->get(request);
doCallback("after get: " + localPath);
...........

The "before get" callback is executed fine but never the one "after get" so I guess it completely freezes when manager is trying the Get() method. Have I missed something or is this just plain impossible through an DLL?

yeye_olive
8th August 2012, 16:38
It is unclear to me what is wrong precisely without being able to run some code, but there are a few things to consider:
1. QNetworkManager requires a Qt event loop to be running to function properly. Is that the case in your DLL? (In any case this should not prevent get() from returning.)
2. QNetworkManager may require QCoreApplication to be instanciated, although I could not find anything supporting that intuition in the docs.
3. Are you certain that doCallback("before get: " + remotePath) returns? It might have time to print something and then freeze before returning.
Can you reproduce the problem in a minimal example?