Hi, I am writing a Blackberry app have this problem and would greatly appreciate if someone could help.
The situation is as follows.
I have code:
void MYNetworkClass::requestFinished(QNetworkReply* reply)
{
// Check the network reply for errors
if (reply->error() == QNetworkReply::NoError)
{
// read response
qDebug() <<"Response: "<< response;
JsonDataAccess jda;
QVariantMap results = jda.loadFromBuffer(response).toMap();
QVariantMap data = results.value("SomeData").toMap();
emit signalSuccess(data); // I reach here ....
// however actually when I click "Step Over" in debug mode, and try to exit the function
// afterwards I get such "error" saying: No source available for "QMetaObject::activate() at 0xb9668da7" - highlighted in red.
}
else
{
qDebug() << "\n Problem with the network";
qDebug() << "\n" << reply->errorString();
}
void MYNetworkClass::requestFinished(QNetworkReply* reply)
{
// Check the network reply for errors
if (reply->error() == QNetworkReply::NoError)
{
// read response
const QByteArray response(reply->readAll());
qDebug() <<"Response: "<< response;
JsonDataAccess jda;
QVariantMap results = jda.loadFromBuffer(response).toMap();
QVariantMap data = results.value("SomeData").toMap();
emit signalSuccess(data); // I reach here ....
// however actually when I click "Step Over" in debug mode, and try to exit the function
// afterwards I get such "error" saying: No source available for "QMetaObject::activate() at 0xb9668da7" - highlighted in red.
}
else
{
qDebug() << "\n Problem with the network";
qDebug() << "\n" << reply->errorString();
}
To copy to clipboard, switch view to plain text mode
In MyNetwork class I have also added the signal definition in the header file:
signals:
void signalSuccess(QVariantMap result);
signals:
void signalSuccess(QVariantMap result);
To copy to clipboard, switch view to plain text mode
Now, elsewhere when someone calls a method of MyNetworkClass object which invokes requestFinished,
I want to catch the signal that is emitted by the requestFinished - as shown above.
MyNetworkClass *network = new MyNetworkClass();
QMap<QString, QString> params;
params.insert("username", userEmail);
bool res
= QObject::connect(network,
SIGNAL(signalSuccess
(QVariantMap
)),
this,
SLOT(SomeSlotForSignal
(QVariantMap
)));
Q_ASSERT(res);
Q_UNUSED(res);
network->makePostRequest("Login");
MyNetworkClass *network = new MyNetworkClass();
QMap<QString, QString> params;
params.insert("username", userEmail);
bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
Q_ASSERT(res);
Q_UNUSED(res);
network->makePostRequest("Login");
To copy to clipboard, switch view to plain text mode
My problem is that the slot SomeSlotForSignal never gets called..
( even though the signal is emitted form the requestFinished method and also I have declared SomeSlotForSignal as a slot in the header file ... What can be problem??? Any help??? Thanks.
Added after 18 minutes:
I have solved the problem.
The code I wrote above was contained in some method Say MyMethod of class B.
void ClassB::MyMethod(int param1, int param 2)
{
MyNetworkClass *network = new MyNetworkClass();
QMap<QString, QString> params;
params.insert("username", userEmail);
bool res
= QObject::connect(network,
SIGNAL(signalSuccess
(QVariantMap
)),
this,
SLOT(SomeSlotForSignal
(QVariantMap
)));
Q_ASSERT(res);
Q_UNUSED(res);
network->makePostRequest("Login");
void ClassB::MyMethod(int param1, int param 2)
{
MyNetworkClass *network = new MyNetworkClass();
QMap<QString, QString> params;
params.insert("username", userEmail);
bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
Q_ASSERT(res);
Q_UNUSED(res);
network->makePostRequest("Login");
To copy to clipboard, switch view to plain text mode
}
and looked like this:
ClassB *object = new ClassB();
object->MyMethod(param1,param2);
ClassB *object = new ClassB();
object->MyMethod(param1,param2);
To copy to clipboard, switch view to plain text mode
before I was not using pointers and heap allocation, I just had:
ClassB object;
object.MyMethod(param1,param2);
ClassB object;
object.MyMethod(param1,param2);
To copy to clipboard, switch view to plain text mode
and I think when the requestFinished returned, the above object was already destroyed. ?????
I think/hope so.. Do you think it is correct reasoning???
Bookmarks