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
hungcotac
Posts: 77
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 

Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

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
Please use plain text.
Developer
hungcotac
Posts: 77
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 ?
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

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
Please use plain text.