Results 1 to 6 of 6

Thread: Declaring a slot without "public slots:" declaration?

  1. #1
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Question 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:
    Qt Code:
    1. #define MY_METHODS() \
    2. public: \
    3. int myMethod1( int a, int b ); \
    4. int myMethod2( int a, int b );
    5.  
    6.  
    7. class MyClass : public QObject
    8. {
    9. Q_OBJECT
    10. MY_METHODS();
    11. Q_DECLARE_SLOT( int myMethod1 int int ); // or something similar
    12. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Declaring a slot without "public slots:" declaration?

    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

  3. #3
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Declaring a slot without "public slots:" declaration?

    I don't think this is what I'm looking for.
    Q_SLOT can only be used with a method DECLARATION:
    Qt Code:
    1. Q_SLOT int myMethod1( int a, int b );
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. #define MY_SLOTS( x )
    2.  
    3. #define MY_METHODS() \
    4. public: \
    5. int myMethod1( int a, int b ) { ... }; \
    6. int myMethod2( int a, int b ) { ... }; \
    7. int myMethod3( int a, int b ) { ... }; \
    8. int myMethod4( int a, int b ) { ... };
    9.  
    10.  
    11.  
    12. class MyClass : public QObject
    13. {
    14. Q_OBJECT
    15. MY_METHODS();
    16. MY_SLOTS(
    17. public slots:
    18. int myMethod1( int a, int b );
    19. int myMethod3( int a, int b );
    20. private:
    21. )
    22. };
    To copy to clipboard, switch view to plain text mode 
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Declaring a slot without "public slots:" declaration?

    Why do you want to do this?

  5. #5
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Declaring a slot without "public slots:" declaration?

    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).

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Declaring a slot without "public slots:" declaration?

    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.

Similar Threads

  1. debugging "signal does not reach slot" in a template class
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2010, 16:03
  2. Replies: 1
    Last Post: 5th January 2010, 13:34
  3. Replies: 1
    Last Post: 23rd August 2008, 22:09
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. using "public slots:"
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2006, 23:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.