PDA

View Full Version : Some starter help



WetCode
24th March 2013, 02:27
Hello i have been trying and trying to find a tutorial on QJson and web services.
While i have managed to find some source code on Qt-App i have not been able to find any tutorials on the mather.
What i want to do for my practice project is to .:

#1 Login to Facebook
#2 Get My Profil image.
#3 Post a comment on my wall "Hey my app was here"

So what am asking for is.
Can someone please tell me where to find a tutorial on somthing like this.
It dont have to be facebook ofcorse but somthing teaching how to do that sorta thing step by step.
Nothing big or fancy just somthing that covers the steps needed to send and recive valid data and display it in some meaningfull form.
That whould aply in most cases (If that is posibol?)

Thanks for reading and thanks for any help on this subject its much aprichiated.

Cheers
WetCode

anda_skoa
24th March 2013, 12:59
You could have a look at the KDE Facebook API, I think it uses QJson
http://lxr.kde.org/source/extragear/libs/libkfbapi/libkfbapi/

Cheers,
_

WetCode
24th March 2013, 13:09
I have tryd looking at sources but i was hoping for some explinations with the code.
Somthing that explains the process on how to do it.
I know i sound realy begish here but i have tryd and tryd geting a understanding of this but it keeps evading me.

Edit: So i read over the class refrence for QJson here (http://qt-project.org/doc/qt-5.0/qtcore/json.html#the-json-classes) twice. I also been reading up on Json in general.

But i havent seen anything about a URL in the refrence. So am thinking using it in combination with QNetworkAccessManager. But since i have never used any of them its gona take me some time anyways.
My Qustion is this in the refrence of QJson it mentions a JSON Document like so:

{
"FirstName": "John",
"LastName": "Doe",
"Age": 43,
"Address": {
"Street": "Downing Street 10",
"City": "London",
"Country": "Great Britain"
},
"Phone numbers": [
"+44 1234567",
"+44 2345678"
]
}

Is this the representation of the form on some Web Service?
And do i go in to the source of the web page and get all this "names" Street, City, Country...
As names of the difrent forms on the web page and the values are ofcorse fild in my application somewhere. Downing Street 10","London", "Great Britain"

Sorry for lenght and maybe somewhat stupid qustions but i will rather ask stupid qustions then not to learn new things. :)

Cheers
Wetcode

WetCode
24th March 2013, 18:31
Ok so after some trail and error i got a "downloaded" index page of Facebook.
And things are a bit clearer (litel bit atleast :>) and i came up with this code.
I know its not prety remember am only experementing any tips is great.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(onResult(QNetworkReply*)) );
}

MainWindow::~MainWindow()
{
delete ui;
}

// funtion used to login to facebook
void MainWindow::sendLoginRecuest(QUrl url)
{
url = "https://www.facebook.com/";
netRequest.setUrl(url);
netReply = networkManager.get(netRequest);
}
// response to our login atempt
void MainWindow::reciveRecuest()
{
// Do somthing...
}

// Exit function
void MainWindow::on_actionExit_triggered()
{
close();
}
// Exit function \\

void MainWindow::on_loginButton_clicked()
{
sendLoginRecuest(url);
}
// This is what happens when the request is finsihed
void MainWindow::onResult(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError)
{
QMessageBox::information(this, "Request Error: ",
"Request Faild: ",
QMessageBox::Ok );
} else {
QMessageBox::information(this, "Request Completed: ",
"Request Completed with no errors. ",
QMessageBox::Ok );

ui->textBrowser->setText("Ok test");

QString data = (QString) reply->readAll();
QScriptEngine engine;
QScriptValue result = engine.evaluate(data);

ui->textBrowser->append(data);

}
ui->textBrowser->update();
}

As am shure you can see it just takes the text and puts it in a text browser.
Now am wondering
#1 How to find out what Url to use for the login do i use?

From Facebook source ( <form id="login_form" action="https://www.facebook.com/login.php?login_attempt=1" method="post" onsubmit="return window.Event .... )
#2 is it away for me to use the reply that i get to parse the username and password feald?
And then login?
#3 Or do i get the fealds for the login form manualy in the source code on the page (including the hidden ones?)
#4 Is it the reply.readAll() the correct method to use when trying somthing like this.

Am confused... :p

Thanks to anyone how takes the time to help a newbie out.
Its much aprichiated (Like a kid on christmas i am hehe) :)

Cheers
WetCode

anda_skoa
25th March 2013, 09:30
But i havent seen anything about a URL in the refrence. So am thinking using it in combination with QNetworkAccessManager.

Yes, QJson is just for converting data between JSON and C++ data structures.
How you receive or send the JSON data depends on whatever service you are interacting with. Very often it is via HTTP and so QNetworkAccessManager comes into play there.



My Qustion is this in the refrence of QJson it mentions a JSON Document like so:

{
"FirstName": "John",
"LastName": "Doe",
"Age": 43,
"Address": {
"Street": "Downing Street 10",
"City": "London",
"Country": "Great Britain"
},
"Phone numbers": [
"+44 1234567",
"+44 2345678"
]
}

Is this the representation of the form on some Web Service?

Yes, could be a real web service or just an example.


And do i go in to the source of the web page and get all this "names" Street, City, Country...

Usually web services have some web pages describing their API. That will include URLs to use, how to format data, which data is mandator and which optional, and so on.

EMJAY
25th March 2013, 11:33
Hi everyone. I have used MEL for a few years, but recently started to learn python (3.3.0). Recent discussions with peers have suggested that I should be using pyqt. What I would like to know is which version of pyqt I should be using as a learner and if the version I need is compliant with the version of python I have installed. This is probably a question that has appeared many times, but I would be grateful is anyone could give me some advice. I see that there is qt3 and qt4, but what is the difference?

Relativley new to this language, so please provide suitable responses.

Thanks

EMJAY

WetCode
25th March 2013, 11:59
Thank you som much for your clear answer. Now i know what to read up on next. :)
I have been having tough one understanding the difrent parts here.
Again thanks much aprichiated.

Cheers
WetCode

Added after 10 minutes:

Please dont take this as a defenetly answer am just a Beginner my self and i dont know Python.
But i whould recomend going for the latest version and maybe update the Python version ?
Anyways the newer the version of Qt the more and bether refined goodis you get. :)