Created
January 4, 2012 22:54
-
-
Save ahf/1562660 to your computer and use it in GitHub Desktop.
Test case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ qnam.app/Contents/MacOS/qnam | |
Sending request | |
Value: QVariant(int, 1337) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ qnam.app/Contents/MacOS/qnam | |
Sending request | |
Nope :-( | |
$ qmake --version | |
QMake version 2.01a | |
Using Qt version 5.0.0 in /Users/ahf/src/nokia/qt5/qtbase/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QAuthenticator> | |
#include <QCoreApplication> | |
#include <QNetworkAccessManager> | |
#include <QNetworkReply> | |
#include <QNetworkRequest> | |
#include <QObject> | |
#include <QUrl> | |
#include <QVariant> | |
#include <QtDebug> | |
class TestCase : public QObject { | |
Q_OBJECT | |
public: | |
TestCase(QObject *parent = 0) : | |
QObject(parent) | |
{ | |
m_manager = new QNetworkAccessManager(this); | |
connect(m_manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*))); | |
QObject *originatingObject = new QObject; | |
originatingObject->setProperty("test_case_value", QVariant(1337)); | |
QNetworkRequest request; | |
request.setUrl(QUrl("http://koivi.com/php-http-auth/protect.php")); | |
request.setOriginatingObject(originatingObject); | |
qWarning() << "Sending request"; | |
m_manager->get(request); | |
} | |
~TestCase() | |
{ | |
} | |
private slots: | |
void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) | |
{ | |
Q_UNUSED(authenticator); | |
QObject *originatingObject = reply->request().originatingObject(); | |
if (originatingObject) | |
qWarning() << "Value: " << originatingObject->property("test_case_value"); | |
else | |
qWarning() << "Nope :-("; | |
} | |
private: | |
QNetworkAccessManager *m_manager; | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication application(argc, argv); | |
TestCase test; | |
return application.exec(); | |
} | |
#include "test.moc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment