[Development] [API Change] New authentication method in QNetworkAccessManager
Olivier Goffart
olivier at woboq.com
Sun Mar 9 19:32:28 CET 2014
On Sunday 09 March 2014 15:10:02 Kurt Pattyn wrote:
> Currently, QNAM stalls when authentication is required (also see:
> https://bugreports.qt-project.org/browse/QTBUG-16251). Also, the connection
> between the authenticationRequired signal and the slot must be a direct
> connection. This is problematic when an application wants to show a login
> dialogbox for instance.
>
> I propose to change this implementation by using a delegate authenticator
> instead.
...
> What are your opinions on this?
1) Your suggested change would be binary incompatible. You would need to pick
another class name than QAuthenticator
2) Your change does not seem to fix the problem at all. You get a "blocking"
virtual function instead of a "blocking" signal.
Here is my suggested API change: adding QNetworkReply::pause and
QNetworkReply::resumeAuthentication, to be used as this.
QObject::connect(qnam, &QNetworkManager::authenticationRequired,
[](QNetworkReply * reply, QAuthenticator * authenticator) {
reply->pause(); // New slot: when we return this function it won't continue
auto dialog = new MyPasswordDialog();
dialog->open();
QObject::connect(dialog, &MyPasswordDialog::done, reply, [=]{
authenticator->setUser(dialog->user);
authenticator->setPassword(dialog->password);
reply->resumeAuthentication(authenticator); //new slot;
});
});
Alternative: adding those function to the QAuthenticator itself.
--
Olivier
Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
More information about the Development
mailing list