[SOLVED] download file from link to phone memory using qt???
-
I'm working on a project where I have to download file to phone memory. pls any help??
thanks
-
I think that you can use same approaches as at desktop, why not? You have some path in phone filesystem, you have url. All is the same.
P.S. Moved to more appropriate category.
-
can you provide how to save?? i dont know???
-
Read Qt Assistant about QNetworkAccessManager. I think it will help you.
-
Use "QNetworkAccessManager":http://doc.qt.nokia.com/4.7/qnetworkaccessmanager.html . QNetworkReply inherits QIODevice and I think you should be able to go from there.
-
sorry it does nt help me where to save??? any other option
-
Not tested, but:
@
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *parent = 0) : QObject(parent), manager(new QNetworkAccessManager)
{
reply = manager->get(QNetworkRequest(QUrl("http://example.com")));
connect(reply,SIGNAL(finished()),SLOT(downloaded()));
}public slots:
void downloaded()
{
QFile file("/path/to/file");
file.open(QIODevice::WriteOnly);
file.write(reply.readAll());
file.close();
}private:
QNetworkAccessManager *manager;
QNetworkReply *reply;
}
@EDIT: fixed example
-
have to tried it to download file larger than 2 MB.???
-
Yes, I just did. Works like a charm :)
-
yes, it works great, now i am trying to add progressbar to show how much download is completed.
have you any idea??
-
Use QProgressDialog or implement one by yourself. Qt Assitant and Qt examples contain all info that you need. Try to use them.
-
thanks for help
-
i insert this in the mainwindows.cpp:
@
MainWindow(QMainWindowparent = 0) : QMainWindow(parent), manager(new QNetworkAccessManager)
{
reply = manager->get(QNetworkRequest(QUrl("http://example.com")));
connect(reply,SIGNAL(finished()),SLOT(downloaded()));
}
@
and i get an error: C:\Users\zanotti\aaa-build-desktop..\aaa\mainwindow.cpp:29: error: expected ')' before '=' token -
It should be more like:
@MainWindow::MainWindow(QWidget *parent = 0) : QMainWindow(parent), manager(new QNetworkAccessManager)
{
reply = manager->get(QNetworkRequest(QUrl("http://example.com")));
connect(reply,SIGNAL(finished()),SLOT(downloaded()));
}@