BestTechie Forums: Qt Help - BestTechie Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Qt Help Qhttp request not working locally


#1 User is offline   asoogn1 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 22-July 10

Posted 22 July 2010 - 05:09 PM

I took a stab at creating a program using Qt that would use http to get data from a website and store it in a file. All parts seem to be accounted for but the returned "result.html" file is always blank. Does anybody know why? Here's my code below:

I bound it to a command that executes when a button on the GUI is pushed:

int rID = 0;

void MainWindow::buttonClickHandler2()
{
ui->CurModeOUT->setText(ui->pushButton_2->text());
QHttp http;
QIODevice*pdev = 0;
QFile file("C:\\result.html");
file.open(QIODevice::ReadWrite);
QHttpRequestHeader header ("GET", "http://finance.yahoo.com/");
header.setValue("Host", "www.yahoo.com");
http.setHost("www.yahoo.com", 80);

rID = http.get("/index.html",pdev);
//rid = http.request(header, 0, pdev);
printf("rid %d\n",rID);

QTextStream stream(&file);
pdev = stream.device();
file.flush();
file.close();

QString requestID = QString::number(rID);
ui->DimPctOUT->setText(requestID);
}

#2 User is offline   jcl 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1304
  • Joined: 30-August 04
  • Location:The Internet
  • Operating System:Arch

Posted 22 July 2010 - 07:15 PM

rID = http.get("/index.html",pdev);


pdev is null here, so http returns the data via signals. You need to move

QTextStream stream(&file);
pdev = stream.device();


above the call to QHttp::get() or just pass file to get() instead.

#3 User is offline   asoogn1 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 22-July 10

Posted 23 July 2010 - 12:42 PM

View Postjcl, on 22 July 2010 - 07:15 PM, said:

rID = http.get("/index.html",pdev);


pdev is null here, so http returns the data via signals. You need to move

QTextStream stream(&file);
pdev = stream.device();


above the call to QHttp::get() or just pass file to get() instead.



Hmm, I tried both solutions but the output file result.html is still blank when i open it. Is the path incorrect? Or my use of the QHttp get?

#4 User is offline   asoogn1 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 22-July 10

Posted 23 July 2010 - 12:49 PM

Should I try using QUrlOperator instead? Could you show me how to do that? The API says I need to registed QHttp using qInitNetworkProtocols(). Anyideas?

#5 User is offline   asoogn1 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 22-July 10

Posted 26 July 2010 - 12:38 PM

bump

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users