PDA

View Full Version : HTTP Connection establishment problem



ggdev001
6th February 2013, 07:12
Hello, I am developing app on BB 10 using C++ and I have this code from QT web site where in the end I want to establish HTTP connection with server and get JSON
data. But first here is the code where I also try to register slot and send get request.

// Creates the network access manager and connects a custom slot to its
// finished signal. Checks the return value for errors.
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
bool res = connect(manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));

Q_ASSERT(res);

// Indicate that the variable res isn't used in the rest of the app, to prevent
// a compiler warning
Q_UNUSED(res);


manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));

The problem is that during the debug, the "res" variable is False, after the "connect" line
gets executed. Is this the correct behaviour? thanks.

Lykurg
6th February 2013, 07:25
Have a look at the console. If the connection could not be established there are usually messages at the output. Just a wild guess: have the "this"-class the Q_OBJECT macro?

ggdev001
6th February 2013, 08:21
8683 This is the screenshot, I am not sure it is helpful, quite strangely it mentions some of my two other projects (SampleApp1 and InjectCppIntoXml). PS. Yes, "this" has Q_OBJECT macro.

Added after 33 minutes:

OK I managed to get some output using slog2info. This is what I get at some point during debug: "Feb 02 03:49:59.658 com.example.JSONSample.testDev__JSONSampled2265543 .1154138249
default 9000 Object::connect: No such slot JSONSample::replyFinished(QNetworkReply*) in ../src/JSONSample.cpp:36". Why do I get this message?? I have replyFinished defined both in header and cpp files.

Added after 5 minutes:

I think I found a solution, I guess I had to add following line: "public slots:" to the header file.


public slots:

void replyFinished(QNetworkReply* reply);

Lykurg
6th February 2013, 09:38
hmm, that would have been my second guess after Q_OBJECT...