PDA

View Full Version : Converting a php program to Qt



srohit24
19th March 2009, 07:16
I have written a program that contacts twitter API to get the 20 latest tweets. Here is the code.


<html>
<head><title>
Twitter API
</title></head>
</html>

<?php

$login = "1"; //Add the Username:password for authenticated sessions

$tweets = "http://twitter.com/statuses/public_timeline.xml";

$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $tweets);
curl_setopt($tw, CURLOPT_USERPWD,$login);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);

$twi = curl_exec($tw);
$tweeters = new SimpleXMLElement($twi);
$latesttweets = count($tweeters);

//echo the data

foreach ($tweeters->status as $twit1) {

echo "<div class='name'>",'<b>'.$twit1->user->name.'</b>',"</div>";
echo "<div class='text'>".$twit1->text." <div class='description'>","</div></div></div>";

}

curl_close($tw);

?>

Now i need to write the same thing in Qt. Contacting the twitter API. How can i accomplish it?

thanks

ComaWhite
19th March 2009, 08:49
Read up on this. http://doc.trolltech.com/4.5/qtnetwork.html

srohit24
19th March 2009, 09:50
thanks for replying.

So I need to create a QNetworkAccessManager. Can anyone shed some light on it?

How can i incorporate a browser in my application, how to duplicate wamp and things like that.

I more question.
How can i download all the files that are needed to run this application?

http://doc.trolltech.com/4.5/network-http.html

I have copied all the files and used Qt Open source, but the compiler says errors and wont execute.

wysota
19th March 2009, 09:52
Use QNetworkAccessManager to send a http query.

For a browser use QWebView. As for your other problems, give us more details.

srohit24
19th March 2009, 10:32
What my app must do is this.

Access the twitter API using the public_times
Request latest 20 tweets
Display the tweets

I am new to Qt.


QWebView *view = new QWebView(parent);
view->load(QUrl("http://qtsoftware.com/"));
view->show();

How can i make this sample code for webview run?

thanks

ComaWhite
19th March 2009, 11:56
Starting reading these to help you get started with Qt
http://doc.trolltech.com/4.5/tutorials.html

srohit24
19th March 2009, 18:31
Thanks for the links guys. I have built my own browser using Qt.

Now my question is, what is equivalent to curl in Qt.So that i can contact the Twitter API's.

I have shown you my code in php. I just need a Qt version if it. Is it possible to deal with API's using QT??

wysota
19th March 2009, 19:33
You have already been given the answer. You have even written the class name yourself in this thread.