| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 6 | |
Hi.
I have to make a library for download files from a url. The function what I use from download the files is the next:
void HttpGet::download(const QUrl &url, const QString &filename) {
QFile file;
QHttp http;
QEventLoop loop;
QObject::connect(&http, SIGNAL(done(bool)), &loop, SLOT(quit()));
file.setFileName(filename);
file.open(QIODevice::WriteOnly);
http.setHost(url.host(), url.port(80));
http.get(url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority), &file);
loop.exec();
}
but, when I call to the function, appears the next error:
"QEventLoop: Cannot be used without QApplication"
I need a library, not an application. Can someone help me?
Thanks in advance.
--
[ signature omitted ]
Message 2 in thread
Joan Carles Jimenez wrote:
> Hi.
>
> I have to make a library for download files from a url. The function
> what I use from download the files is the next:
>
> void HttpGet::download(const QUrl &url, const QString &filename) {
>
> QFile file;
>
> QHttp http;
>
> QEventLoop loop;
>
> QObject::connect(&http, SIGNAL(done(bool)), &loop, SLOT(quit()));
>
> file.setFileName(filename);
>
> file.open(QIODevice::WriteOnly);
>
> http.setHost(url.host(), url.port(80));
>
> http.get(url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority), &file);
>
> loop.exec();
>
> }
>
> but, when I call to the function, appears the next error:
>
> "QEventLoop: Cannot be used without QApplication"
>
> I need a library, not an application. Can someone help me?
>
> Thanks in advance.
>
> --
>
> Joan Carles Jimenez
>
> jjcarles@xxxxxxxx
>
I suppose you need to make HttpGet::download(const QUrl &url, const
QString &filename, QEventLoop& loop)
and pass the event loop with every call. QEventLoop is highly connected
to QApplication as it handles all events for QApplication. Despite of
the first impression, it is not asynchronous, but entering loop.exec()
in your code is synchronous, so every event of the application can be
treated inside the event loop, not only the QHttp events.
I'm not sure I explained it clearly? What I mean is: you cannot have
QEventLoop without application.
Best regards,
Pawel Jaworski
--
[ signature omitted ]
On Friday 30 May 2008 15:56:24 Pawel Jaworski wrote: > I suppose you need to make HttpGet::download(const QUrl &url, const > QString &filename, QEventLoop& loop) > and pass the event loop with every call. QEventLoop is highly connected > to QApplication as it handles all events for QApplication. Despite of > the first impression, it is not asynchronous, but entering loop.exec() > in your code is synchronous, so every event of the application can be > treated inside the event loop, not only the QHttp events. > Yes, the code is synchronous. This function is for download a data file. After download, another function (in the same library) plot the values using QWT. > I'm not sure I explained it clearly? What I mean is: you cannot have > QEventLoop without application. > Then, I have a problem. My objective is create a library for extend Python and to call it with "import" command. And I not have a QApplication. Does any solution? Cheers! -- [ signature omitted ]