QNetworkAccessManager on iOS?
-
I'm writting an iPhone app that uses QNetworkAccessManager to download some images from the internet. The following code works on the desktop : The file is downloaded and a list of several configurations are displayed. However on the iPhone no network configurations are found and the file is not downloaded. networkAccessible() returns NotAccessible.
How can I make QNetworkAccessManager work on iOS? Are there any libs/capabilities that I have to include/activate in my .pro file? Any special configuration from the side of XCode?
According to https://codereview.qt-project.org/#change,69298 there should be a NSUrlConnection backend available for iOS but I can't find any instructions on setting it up.
Any help would be greatly appreciated. Thanks
@void main() {
QCoreApplication app;
// only one nam instance in my app
QNetworkAccessManager* nam = new QNetworkAccessManager();
connect (nam, SIGNAL(finished(QNetworkReply*)), receiver, SLOT(onFinished(QNetworkReply*)));app.exec();
}
// this is called from inside the event loop
void fetch() {
foreach (QNetworkConfiguration config, nam->allConfigurations()) {
qDebug() << config.name();
}QUrl url("http://..../A.png"); nam->get(QNetworkRequest(url));
}
// this is the receiver's slot
void onFinished(QNetworkReply* reply) {
doSomething();
}@Qt 5.2 | iOS 7.0 on iPhone5
-
You can try Qt examples involving QNetworkAccessManager.
By the way, please check the network connection of your iOS device.
-
Thanks for your quick answer. Problem solved. There was nothing wrong with the code of course. I simply had to enable the network link conditioner in the Developer menu of my iPhone. Thanks for pointing that out.
QNetworkAccessManager works like a charm on iOS !