Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QNetworkAccessManager and authenticationRequired [closed]

Tags:

c++

qt

qt4

Help me write program work with protocol FTP and authentication by login password using QnetworkAccessManager. I implement connect to server and get directory listing, but i dont undestend how implement authentication. I read article http://doc.qt.nokia.com/qq/32/qq32-webkit-protocols.html.

My source in attach https://rapidshare.com/files/457472584/zip.zip.

Qt 4.7 Windows Xp Linux

like image 911
user709500 Avatar asked Nov 01 '25 01:11

user709500


1 Answers

I'm doing something similar and need to solve the very same problem:
What I do is:
- create the QNetworkAccessManager object, and connect the signal authenticationRequired

m_ftpManagerPtr = new QNetworkAccessManager(this);
Q_ASSERT(m_ftpManagerPtr);
connect ( m_ftpManagerPtr,
          SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
          this,        
          SLOT(onAuthenticationRequestSlot(QNetworkReply*,QAuthenticator*)) );

Inside the slot function I simply populate the user name and password fields/variable:

void QacFtpClient::onAuthenticationRequestSlot(QNetworkReply *aReply, 
                                               QAuthenticator *aAuthenticator)
{
    qDebug() << Q_FUNC_INFO;
    aAuthenticator->setUser(m_ftpUser);
    aAuthenticator->setPassword(m_ftpPasswd);
}

And that's it... it automagically works ;)

like image 196
sergico Avatar answered Nov 02 '25 15:11

sergico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!