April 1, 2011

rishabhc rishabhc
Lab Rat
10 posts

[Solved]How to call a PHP script on localhost using Qt?

 

Hello,

I am developing an app which broadly does the following:
1. Accepts from the user an html file
2. Runs a php script to make changes to the html
3. Returns the changed html back to the user to view

How can I call the PHP script in Qt? I am using Apache running on my localhost

5 replies

April 1, 2011

Volker Volker
Ant Farmer
5428 posts

I would call the PHP command line tool. See the wiki article [developer.qt.nokia.com] for an example. It calls the applescript interpreter on OS X, but it’s basically the same for the PHP command line tool.

April 1, 2011

dialingo dialingo
Lab Rat
158 posts

You can use QNetworkAccessManager to access a page on localhost to trigger the included PHP script. See the documentation of QNetworkAccessManager how you can do this.

April 1, 2011

rishabhc rishabhc
Lab Rat
10 posts

Thanks. I will try these and post back the progress

April 1, 2011

2beers 2beers
Lab Rat
149 posts

you make a http request to your localhost http server(in your case apache server)
more info you can find here: Qt http request [wiki.forum.nokia.com]

for example you have the following php pahe in your htdocs directory: test.php

  1. // test.php
  2. echo("hello world");

you just access your page : http://localhost/test.php

  1. QUrl url("http://localhost/test.php");
  2. QNetworkReply* reply = nam->get(QNetworkRequest(url));

June 3, 2011

rishabhc rishabhc
Lab Rat
10 posts

Thanks. Using QNetworkAccessManager and QNetworkReply answered the requirement.

 
  ‹‹ QFileSystemWatcher      How to move one QAxObject from one thread to another ››

You must log in to post a reply. Not a member yet? Register here!