Results 1 to 7 of 7

Thread: Some starter help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Some starter help

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Some starter help

    You could have a look at the KDE Facebook API, I think it uses QJson
    http://lxr.kde.org/source/extragear/...api/libkfbapi/

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    WetCode (24th March 2013)

  4. #3
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Some starter help

    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 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:
    Qt Code:
    1. {
    2. "FirstName": "John",
    3. "LastName": "Doe",
    4. "Age": 43,
    5. "Address": {
    6. "Street": "Downing Street 10",
    7. "City": "London",
    8. "Country": "Great Britain"
    9. },
    10. "Phone numbers": [
    11. "+44 1234567",
    12. "+44 2345678"
    13. ]
    14. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by WetCode; 24th March 2013 at 14:37.

  5. #4
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Re: Some starter help

    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.
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
    10. this, SLOT(onResult(QNetworkReply*)) );
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. // funtion used to login to facebook
    19. void MainWindow::sendLoginRecuest(QUrl url)
    20. {
    21. url = "https://www.facebook.com/";
    22. netRequest.setUrl(url);
    23. netReply = networkManager.get(netRequest);
    24. }
    25. // response to our login atempt
    26. void MainWindow::reciveRecuest()
    27. {
    28. // Do somthing...
    29. }
    30.  
    31. // Exit function
    32. void MainWindow::on_actionExit_triggered()
    33. {
    34. close();
    35. }
    36. // Exit function \\
    37.  
    38. void MainWindow::on_loginButton_clicked()
    39. {
    40. sendLoginRecuest(url);
    41. }
    42. // This is what happens when the request is finsihed
    43. void MainWindow::onResult(QNetworkReply *reply)
    44. {
    45. if (reply->error() != QNetworkReply::NoError)
    46. {
    47. QMessageBox::information(this, "Request Error: ",
    48. "Request Faild: ",
    49. QMessageBox::Ok );
    50. } else {
    51. QMessageBox::information(this, "Request Completed: ",
    52. "Request Completed with no errors. ",
    53. QMessageBox::Ok );
    54.  
    55. ui->textBrowser->setText("Ok test");
    56.  
    57. QString data = (QString) reply->readAll();
    58. QScriptEngine engine;
    59. QScriptValue result = engine.evaluate(data);
    60.  
    61. ui->textBrowser->append(data);
    62.  
    63. }
    64. ui->textBrowser->update();
    65. }
    To copy to clipboard, switch view to plain text mode 
    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?
    Qt Code:
    1. From Facebook source ( <form id="login_form" action="[B][FONT=Arial Black]https://www.facebook.com/login.php?login_attempt=1[/FONT][/B]" method="post" onsubmit="return window.Event .... )
    To copy to clipboard, switch view to plain text mode 
    #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...

    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
    Last edited by WetCode; 24th March 2013 at 18:48.

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Some starter help

    Quote Originally Posted by WetCode View Post
    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.


    Quote Originally Posted by WetCode View Post
    My Qustion is this in the refrence of QJson it mentions a JSON Document like so:
    Qt Code:
    1. {
    2. "FirstName": "John",
    3. "LastName": "Doe",
    4. "Age": 43,
    5. "Address": {
    6. "Street": "Downing Street 10",
    7. "City": "London",
    8. "Country": "Great Britain"
    9. },
    10. "Phone numbers": [
    11. "+44 1234567",
    12. "+44 2345678"
    13. ]
    14. }
    To copy to clipboard, switch view to plain text mode 

    Is this the representation of the form on some Web Service?
    Yes, could be a real web service or just an example.

    Quote Originally Posted by WetCode View Post
    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.

  7. The following user says thank you to anda_skoa for this useful post:

    WetCode (25th March 2013)

  8. #6
    Join Date
    Mar 2013
    Posts
    1
    Platforms
    Windows

    Default Re: Some starter help

    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

  9. #7
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Some starter help

    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.
    Last edited by WetCode; 25th March 2013 at 11:59.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.