[SOLVED] download file from link to phone memory using qt???
-
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.
-
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.
-
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
-
Use QProgressDialog or implement one by yourself. Qt Assitant and Qt examples contain all info that you need. Try to use them.
-
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()));
}@