PDA

View Full Version : need help for QHttp



patcito
31st May 2006, 16:08
I tried wysota's example I found here http://www.qtcentre.org/forum/showpost.php?p=12547&postcount=6



QHttp http;
QFile file("writetothisfile.txt");
file.open(QIODevice::WriteOnly);
http.get("http://www.ietf.org/iesg/1rfc_index.txt", &file);


but this only creates an empty writetothisfile.txt although http://www.ietf.org/iesg/1rfc_index.txt is not empty.

Any idea what I'm doing wrong?

thanx in advance

Pat

whoops.slo
31st May 2006, 17:03
do you call file->close() right after the last line? Try call it using requestFinish(), so the app. will have the time to fill it...

I have a question with the same topic. I have to search several pages. on the first page i have to find all the links and go to that pages to search for specific links. (the task is to list all the links on several blogs that are listed on the first page).
I do that using QHttp. I download the first page and put all link/blogs on that page in a database. Then I try to do download the rest. But when the app. download first couple links it start's making empty files (that eventually gets some data). But then it stops with error: Found and error: Request Aborted.

What happened?

Regards,
Luka

Edit: The problem was in url.Path(), since it looks like QHttp can't handle URL like: "http://ww.example.com/?w=something". URL like "http://www.example.com/something" gives an empty file, but URL like "http://www.example.com/something/" works fine. URL like "http://www.example.com/index.php?com=something&id=same" gives only index.php without the content... Any solutions?

wysota
31st May 2006, 17:40
I tried wysota's example(...)

The example doesn't work. You have to change:


http.get("http://www.ietf.org/iesg/1rfc_index.txt", &file);
into

http.setHost("www.ietf.org");
http.get("/iesg/1rfc_index.txt", &file);

And remember to have an event loop active.


I have a question with the same topic. I have to search several pages. on the first page i have to find all the links and go to that pages to search for specific links. (the task is to list all the links on several blogs that are listed on the first page).
I do that using QHttp. I download the first page and put all link/blogs on that page in a database. Then I try to do download the rest. But when the app. download first couple links it start's making empty files (that eventually gets some data). But then it stops with error: Found and error: Request Aborted.

Can we see the code which dispatches the requests?

whoops.slo
31st May 2006, 18:16
it's a bit messy and in slovene lang. but i hope you will be able to read it. The whole source is in the att.
I'm still learning C++ as well as Qt and this is my first experiment with Qhttp so if you have any better solutions please let me know...

Regards,
Luka

Edit: See my previous post... tnx

patcito
31st May 2006, 18:23
And remember to have an event loop active.
what do you mean? could you give me an example please?

thanx in advance

Pat

jpn
31st May 2006, 18:48
patcito:



From QHttp docs (http://doc.trolltech.com/4.1/qhttp.html):
The class works asynchronously, so there are no blocking functions. If an operation cannot be executed immediately, the function will still return straight away and the operation will be scheduled for later execution. The results of scheduled operations are reported via signals. This approach depends on the event loop being in operation.


QHttp::get() is one of QHttp's asynchronous functions. The function does not block and returns immediately. You'll get notified by signals when the request is started/finished/done..

You don't have to care about this in a GUI application's main thread, as you already have an event loop running. But if you're using QHttp in another threads, you'll need to enter to an event loop in those threads.

patrik08
31st May 2006, 19:02
i have build a Gui_Wget whitout ui file...

And i put to static libs .... to work on all file only include gui_wget.h and get file

&& look QProgressBar *progressDialog; + slot to next .... automatic...

Have a look.....

http://ciz.ch/svnciz/forms_shop/lib_sqlite_qt4/gui_wget.cpp
http://ciz.ch/svnciz/forms_shop/lib_sqlite_qt4/gui_wget.h

Make a list from file Qlist<qstringlist> and loop all




void DB_Setup::Wget_File(int pos , QString u , QString f , QString user , QString pass )
{
/*file_put_contents_append("res.dat",QString( "Prendileo %1" ).arg( QString::number(pos)));*/
get_file = new Gui_Wget(this);
get_file->show();
get_file->OrderGetUrl(u,f,user,pass); /* URL , Localfile , USER, PASS */
connect( get_file, SIGNAL( ready_action() ), this, SLOT( incomming_next() ) );
}

patcito
31st May 2006, 21:12
you'll need to enter to an event loop in those threads.
and how would I do this? :)

patrik08
31st May 2006, 21:29
My loop of file is a xml config file....

and import remote db and file .... evry file open a popup show the progress from 0 to 100
by 100 close and open the next .... you cann make a list by xml or sql...


<?xml version="1.0" encoding="UTF-8"?>
<wget xmlns:cms="http://www.pulitzer.ch/2005/PuliCMS/1.0">
<requestfile sqlurl="http://ppk.ciz.ch/qt_c++/db/customers.sql" localname="1sampledata.sql" />
<requestfile sqlurl="http://ppk.ciz.ch/qt_c++/db/customers.sql" localname="2sampledata.sql" />
</wget>

have a look on ... is a svn (subversion dir if you like...)

http://ciz.ch/svnciz/forms_shop/forms_shop/db_setup.cpp

jpn
1st June 2006, 07:00
and how would I do this? :)
int QThread::exec () [protected] (http://doc.trolltech.com/4.1/qthread.html#exec)