Results 1 to 5 of 5

Thread: QNetworkAccessManager authenticationRequired slot doesn't get called

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 08:48. Reason: code tags

Similar Threads

  1. Slot doesn't get called
    By waynew in forum Qt Programming
    Replies: 7
    Last Post: 18th April 2010, 13:34
  2. QNetworkAccessManager doesn't work
    By Floppy in forum Newbie
    Replies: 7
    Last Post: 14th November 2009, 16:32
  3. How come this slot doesn't get called every second?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 23:41
  4. commitData doesn't seem to be called...
    By tone in forum Qt Programming
    Replies: 7
    Last Post: 10th September 2008, 14:42
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 11: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.