Results 1 to 5 of 5

Thread: using "public slots:"

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default using "public slots:"

    Hello all,
    silly question, I suppose, but: is there any disadvantage in declaring public functions in a class, per default, as public slots ? That is, even though the "slot" aspect may never be used.

    thanks,
    Kev

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using "public slots:"

    IMO it will only make the code bigger.

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using "public slots:"

    ^^^^ Ditto.

  4. #4
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using "public slots:"

    Quote Originally Posted by TheKedge
    Hello all,
    silly question, I suppose, but: is there any disadvantage in declaring public functions in a class, per default, as public slots ? That is, even though the "slot" aspect may never be used.

    thanks,
    Kev
    Kev,
    I am curious. What would be the purpose for doing that?

  5. #5
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using "public slots:"

    Other disadvantage may be that it produces a little more confusing, or at least, not as intuitive interface and design. For example it makes very little sense to make any accessor methods slots. For example in this toy class:

    Qt Code:
    1. class Point2D
    2. {
    3. public:
    4. Point2D(double x, double y) : m_x(x), m_y(y) {}
    5.  
    6. public slots:
    7. double x() { return m_x; }
    8. double y() { return m_y; }
    9.  
    10. private:
    11. double m_x;
    12. double m_y;
    13. };
    To copy to clipboard, switch view to plain text mode 

    This is a joke of a code that I just typed up, but nevertheless, it makes very little sense for x() and y() functions to be slots. If I had documentation comments, doxygen would pick them up as slots and document them as such. This would lead to the client using the Point2D class to believe that these are slots, which is kind of unintuitive considering using these functions as slots woulb be silly. I don't know if I explained this well, but it's kind of a disadvantage I think. Maybe I am just being picky. I know it's not technical, like jacek's point. There could be also other situations where making a function a slot doesn't really make sense, depending on the context, design, etc...

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.