I'm trying to simplify (i.e. get rid of loads of boilerplate code) the creation of functions in a class that have to be marked as "INVOKABLE".
(very much like this other question other question)
To start small, I'm just trying it with one function:
#define CONCAT_NOEXPAND(A, B) A ## B
#define CONCAT(A, B) CONCAT_NOEXPAND(A, B)
#define HANDLER_PREFIX handler_
#define HANDLER_SIGNATURE (QString action, QString parameters)
#define GENERATE_HANDLER_SIGNATURE(ACTION) CONCAT(HANDLER_PREFIX, ACTION) HANDLER_SIGNATURE
#define GENERATE_HANDLERS(NAME) void GENERATE_HANDLER_SIGNATURE(NAME);
class Test : public QObject
{
Q_OBJECT
public:
explicit Test(QObject *parent = nullptr);
private:
Q_INVOKABLE void handler_Test1 (QString, QString); // Ok
Q_INVOKABLE GENERATE_HANDLERS(Test2) // Error!!
}
Using the MACRO GENERATE_HANDLERS
produce this errors:
- error: pasting "handler_" and "(" does not give a valid preprocessing token
#define HANDLER_PREFIX handler_
- error: expected unqualified-id before ‘void’ void GENERATE_HANDLER_SIGNATURE(NAME);
I've also tried to include Q_INVOKABLE
directly in the MACRO GENERATE_HANDLERS
, this results in a code that compile but the functions are not being exported.
Any ideas?