Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Object::connect: No such slot error

 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::smileysurprised:nGetReply(*mAppContainer) in ../src/HttpPostFromCpp.cpp:146

 

Could you tell me what I am missing here.

 

Thanks,

Shwarup Biswas
Developer
nonesuchnick
Posts: 103
Registered: ‎02-13-2012
My Device: Z10 LE

Re: Object::connect: No such slot error

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)));
Learn to run and get in shape with Couch 2AnyK Pro, a Built for BlackBerry native Couch to 5K (C25K) app for BlackBerry 10, available in BlackBerry World.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Re: Object::connect: No such slot error

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::smileysurprised: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);

 

Thanks,

Shwarup Biswas
Developer
nonesuchnick
Posts: 103
Registered: ‎02-13-2012
My Device: Z10 LE

Re: Object::connect: No such slot error

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.html#signals-and-slots-with-default-arguments

 

QNetworkReply* reply = m_networkAccessManager->post(request, body.toAscii());
    connect(reply, SIGNAL(finished()), this, SLOT(onGetReply(ApplicationContainer&)));
Learn to run and get in shape with Couch 2AnyK Pro, a Built for BlackBerry native Couch to 5K (C25K) app for BlackBerry 10, available in BlackBerry World.
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Re: Object::connect: No such slot error

Hi Nonesuchnick,

 

Now I am not getting getting bellow message:

 

QObject::connect: Incompatible sender/receiver arguments

QNetworkReplyImpl::finished() --> HttpPostFromCpp::smileysurprised:nGetReply(ApplicationContainer&)

 

I am having some difficulty to find how it is incompatible?

 

 

Thanks,

Shwarup Biswas
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Object::connect: No such slot error

[ Edited ]

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.


Andrey Fidrya, @zmeyc on twitter
Developer
Shwarup
Posts: 93
Registered: ‎08-18-2011
My Device: 9550

Re: Object::connect: No such slot error

Hi,

Actually I want to pass pass a custom class object in SLOT
Thanks,

Shwarup Biswas
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Object::connect: No such slot error

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.

 


Andrey Fidrya, @zmeyc on twitter