01-30-2013 01:19 PM
I want to pass a custom class object in SLOT
QNetworkReply* reply = m_networkAccessManager->post(request, body.toAscii());
connect(reply, SIGNAL(finished()), this, SLOT(onGetReply(*mAppContainer)));
In this code "mAppContainer" is my custom class object.
In .cpp I implemented this SLOT as bellow:
void HttpPostFromCpp::onGetReply(ApplicationContainer &mAppContainer)
{
}
In .hpp I decleared as bellow:
private Q_SLOTS: void onGetReply(ApplicationContainer &mAppContainer);
I am getting bellow error:
Object::connect: No such slot HttpPostFromCpp:
nGetReply(*mAppContainer) in ../src/HttpPostFromCpp.cpp:146
Could you tell me what I am missing here.
01-30-2013 01:49 PM
I ran into this same issue and it took me a while to realize exactly what the error message meant. When connecting the signals and slots in the connect() method, at least for the slot method, you need to use the TYPE of the parameter that will be passed, not the parameter itself (which results in the error because this method signature does not exist). The code below should work (or at least not give this error):
QNetworkReply* reply = m_networkAccessManager->post(request, body.toAscii());
connect(reply, SIGNAL(finished()), this, SLOT(onGetReply(ApplicationContainer)));
01-30-2013 02:19 PM
Hi Nonesuchnick,
Thanks for your help.
I made the changes as you suggested and tested again but still getting error as bellow.
Object::connect: No such slot HttpPostFromCpp:
nGetReply(ApplicationContainer) in ../src/HttpPostFromCpp.cpp:143
Is bellow code is correct?
In .cpp I implemented this SLOT as bellow:
void HttpPostFromCpp::onGetReply(ApplicationContainer &mAppContainer)
{
}
In .hpp I decleared as bellow:
private Q_SLOTS: void onGetReply(ApplicationContainer &mAppContainer);
01-30-2013 02:49 PM
Sorry, looking at how you defined the slot, the the type of the argument to onGetReply() would be ApplicationContainer&. So the below should work (no compiler error), but I'm not sure it's actually correct.
According to the Qt signals and slots documentation, a SIGNAL must NOT have fewer arguments than the signature passed to SLOT, otherwise a runtime error will occur. This may just be for signals and slots with arguments that have default values though.
http://qt-project.org/doc/qt-4.8/signalsandslots.h
QNetworkReply* reply = m_networkAccessManager->post(request, body.toAscii());
connect(reply, SIGNAL(finished()), this, SLOT(onGetReply(ApplicationContainer&)));
01-30-2013 03:38 PM
Hi Nonesuchnick,
Now I am not getting getting bellow message:
QObject::connect: Incompatible sender/receiver arguments
QNetworkReplyImpl::finished() --> HttpPostFromCpp:
nGetReply(ApplicationContainer&)
I am having some difficulty to find how it is incompatible?
01-30-2013 03:45 PM - edited 01-30-2013 03:46 PM
Hi! Remove the argument from slot and it should work.
Slots must have the same (or lesser) number of arguments as the signals. The argument types and order must match.
finished() signal has no arguments so onGetReply slot also shouldn't have any arguments.
01-30-2013 03:59 PM
01-30-2013 04:13 PM
Signals have predefined arguments. You can't bind additional arguments to the slot. The object which sends the signal knows nothing about how to send these extra arguments.
If you need to pass additional data to signal handler, just store it in member variables. I suppose mAppContainer is already a member variable, so you can access it directly in slot handler.