View Full Version : Declaring a slot without "public slots:" declaration?
I need to use macros to declare methods in my classes, some of which should be slots.
But MOC does not resolve macros, so I cannot simply put "public slots:" instead of "public:" declaration within the macro (see example below).
Is there a way of telling the MOC to create a slot from an already declared method?
An equivalent for hypothetical Q_DECLARE_SLOT macro in this (trivial) example:
#define MY_METHODS() \
public: \
int myMethod1( int a, int b ); \
int myMethod2( int a, int b );
class MyClass : public QObject
{
Q_OBJECT
MY_METHODS();
Q_DECLARE_SLOT( int myMethod1 int int ); // or something similar
};
tbscope
24th May 2010, 19:28
What are you trying to achieve?
I don't know why you want to do this.
But try: http://doc.qt.nokia.com/4.6/qobject.html#Q_SLOT
I don't think this is what I'm looking for.
Q_SLOT can only be used with a method DECLARATION:
Q_SLOT int myMethod1( int a, int b );which in this case would result in redeclaration/overloading error
Or am I wrong? How am I supposed to use it?
I have created this hack for the MOC precompiler:
#define MY_SLOTS( x )
#define MY_METHODS() \
public: \
int myMethod1( int a, int b ) { ... }; \
int myMethod2( int a, int b ) { ... }; \
int myMethod3( int a, int b ) { ... }; \
int myMethod4( int a, int b ) { ... };
class MyClass : public QObject
{
Q_OBJECT
MY_METHODS();
MY_SLOTS(
public slots:
int myMethod1( int a, int b );
int myMethod3( int a, int b );
private:
)
};
The compiler simply ignores everything within MY_SLOTS(...) and does not redeclare following methods.
But MOC does interpret this part and generates the code I need.
tbscope
24th May 2010, 21:45
Why do you want to do this?
I want to use macros to automatize creation of methods. So that instead of declaring several methods and then their several implementations I can just insert one macro call with certain parameters.
But I need some of them to be slots, so that I can access them from a QScriptEngine.
I hope future versions of MOC will support macros, or at least have the tag I needed (Q_DECLARE_SLOT or similar).
squidge
24th May 2010, 22:20
Sounds like what you need is a decent code completion engine such as VAX that let you define your class structure and then let you automatically create the appropriate implementation from those declarations.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.