Results 1 to 5 of 5

Thread: QNetworkAccessManager authenticationRequired slot doesn't get called

  1. #1
    Join Date
    Mar 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QNetworkAccessManager authenticationRequired slot doesn't get called

    Hi,

    I want to access site using QNetworkAccessManager which requires authentication.
    I have written sample code to login to particular site by using Post method but its not working.
    Refer below code:

    Qt Code:
    1. #include "tikonalogin.h"
    2. #include "ui_tikonalogin.h"
    3.  
    4. tikonalogin::tikonalogin(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::tikonalogin)
    7. {
    8. ui->setupUi(this);
    9. acc = new QNetworkAccessManager(this);
    10.  
    11. connect(acc,SIGNAL(finished(QNetworkReply*)),this,SLOT(accFinish(QNetworkReply*)));
    12.  
    13. connect(acc,SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),this,SLOT(authReq(QNetworkReply*,QAuthenticator*)));
    14. }
    15.  
    16. tikonalogin::~tikonalogin()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void tikonalogin::on_goButton_clicked()
    22. {
    23.  
    24. QNetworkRequest request;
    25. QUrl url ("https://www.whatever.in/login.do");
    26.  
    27. QByteArray data;
    28. QUrl param;
    29. param.addQueryItem("type","2");
    30. param.addQueryItem("username","abc");
    31. param.addQueryItem("password","123");
    32. data = param.encodedQuery();
    33. // QString typ,username,password;
    34. // typ="2";
    35. // username="abc";
    36. // password="123";
    37.  
    38. //request.setRawHeader("Authorization","Basic "+QByteArray(QString("%1:%2:%3").arg(typ).arg(username).arg(password).toAscii().toBase64()));
    39. request.setUrl(url);
    40. reply = acc->post(request,data);
    41. //reply = acc->get(request);
    42.  
    43. connect(reply,SIGNAL(readyRead()),this,SLOT(readdata()));
    44. }
    45.  
    46. void tikonalogin::accFinish(QNetworkReply *rep)
    47. {
    48. qDebug() << "Finished";
    49. }
    50.  
    51. void tikonalogin::readdata(){
    52. qDebug() << "Inside readdata()";
    53. QByteArray arr = reply->readAll();
    54. QString s = arr.data();
    55. // qDebug() << s;
    56. // ui->txDetails->setText(s);
    57. }
    58.  
    59. void tikonalogin::authReq(QNetworkReply *, QAuthenticator *a){
    60. qDebug() << "Authenticating";
    61. a->setOption("type",2);
    62. a->setUser("1103544735");
    63. a->setPassword("Tech1234");
    64. }
    To copy to clipboard, switch view to plain text mode 


    Please help me on this.
    Thanks in advance.
    Last edited by high_flyer; 28th April 2011 at 09:48. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager authenticationRequired slot doesn't get called

    "Not working" is very general.
    Many things can be "not working".
    Debug your code, and find the bit of code which is "not working".
    Then we can look in to why it is "not working".
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkAccessManager authenticationRequired slot doesn't get called

    It won't get called unless the web server returns an HTTP status 401. This in unlikely if you are passing valid credentials appropriate to the web site/page in the headers/payload of the request. You seem to be doing that above.

  4. #4
    Join Date
    Mar 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool Re: QNetworkAccessManager authenticationRequired slot doesn't get called

    Hi High_flyer,

    What are you replying man. I dont know thats why i am posting a question.
    If you know then reply with some valid answer or else don't...
    Obviously i am debugging it, but i am not getting the solution.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager authenticationRequired slot doesn't get called

    Don't you get it that I am not your foe but your friend?
    When you post a question, and you want help, you should help others help you.
    Show and mention what you have done to pint point the problem.
    Obviously i am debugging it
    Not obvious from what you have posted.
    It would have been obvious if you had said which part of the code does work as you expect, which doesn't, and what have you done so far for debugging.
    This way potential helpers can know in advance what you have tried, and not suggest it again, and think in lines that are better suited to solving your problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Slot doesn't get called
    By waynew in forum Qt Programming
    Replies: 7
    Last Post: 18th April 2010, 14:34
  2. QNetworkAccessManager doesn't work
    By Floppy in forum Newbie
    Replies: 7
    Last Post: 14th November 2009, 17:32
  3. How come this slot doesn't get called every second?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 6th November 2009, 00:41
  4. commitData doesn't seem to be called...
    By tone in forum Qt Programming
    Replies: 7
    Last Post: 10th September 2008, 15:42
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 12:30

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.