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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 88
Registered: ‎01-05-2013
My Device: BB10
My Carrier: Viettel
Accepted Solution

no such slot ERROR

I want to create Timeout slot:

file TestYourReflex.hpp

#ifndef TestYourReflex_HPP_
#define TestYourReflex_HPP_

#include <QObject>
#include <QTimer>
#include <QTime>


namespace bb { namespace cascades { class Application; }}

/*!
 * @brief Application pane object
 *
 *Use this object to create and init app UI, to create context objects, to register the new meta types etc.
 */
class TestYourReflex : public QObject
{
    Q_OBJECT
public:
    TestYourReflex(bb::cascades::Application *app);
    virtual ~TestYourReflex() {};
public slots:
    void Timeout(int a);

};


#endif /* TestYourReflex_HPP_ */

 

file TestYourReflex.cpp

// Default empty project template
#include "TestYourReflex.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Container>
#include <bb/cascades/Color>

using namespace bb::cascades;

TestYourReflex::TestYourReflex(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	// create root object for the UI
	AbstractPane *root = qml->createRootObject<AbstractPane>();
	QTimer *timer = new QTimer(this);
	timer->setInterval(1000);
	timer->start();
	connect(timer, SIGNAL(timeout()), this, SLOT(Timeout(seed)));
	// set created root object as a scene
	app->setScene(root);
}

void TestYourReflex::Timeout(QTimer *timer){
	qDebug() << "timeout";
	timer->stop();


}



 when the Timeout() function doesn't have param QTimer * timer this code work very well. but when I pass QTimer *timer param like above. the code doesn't work and a got this ERROR 

 

NOTICE Object::connect: No such slot TestYourReflex::Timeout(seed) in ../src/TestYourReflex.cpp:23

 

any one can help me 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: no such slot ERROR

[ Edited ]

You can't pass additional parameters to slots. Their signatures must be the same as signal signatures.

 

It's allowed to omit signal parameters in slots, but changing any of the types or passing additional data is not allowed.

 

In this case a possible solution is declaring QTimer * in the header file as a member variable.

Declare other variables which you need to access in multiple functions the same way.

 

Don't forget to remove 'int a' in slot params or it won't work:

 

class QTimer;

class TestYourReflex : public QObject
{
    Q_OBJECT
public:
    TestYourReflex(bb::cascades::Application *app);
    virtual ~TestYourReflex() {};
public slots:
    void onTimeout();

protected:
    QTimer *timer_;
};

 In .cpp:

 

	timer_ = new QTimer(this);
	timer_->setInterval(1000);
	timer_->start();
QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout()));

 ...

void TestYourReflex::onTimeout(){
	qDebug() << "timeout";
	timer_->stop();
}

 

P.s. There's also QTimer::singleShot(1000, this, SLOT(onTimeout())) which fires the timer only once and doesn't require declaring a variable.

 

P.s.s. A Qt convention is to start variable and method names with lowercase letters. Uppercase is for types, so they can be easily distinguished from variables.


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 88
Registered: ‎01-05-2013
My Device: BB10
My Carrier: Viettel

Re: no such slot ERROR

Yup. So we can't pass argument. But can you tell me why Qt make this limit ? for what ?
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: no such slot ERROR

I guess signals are designed to be similar to function declarations.

The actual data is passed when emitting a signal (similar to calling a function). The main difference is that a function can have only one implementation, but signal can be attached to multiple slots and these connections can be reconfigured at runtime.

Andrey Fidrya, @zmeyc on twitter