Results 1 to 8 of 8

Thread: private slots ??

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default private slots ??

    can a slot be private ....if it can be then does it has the same meaning as private variables or function ??..

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: private slots ??

    yes, slots can be private.
    Slots are normal C++ functions and can be called normally; their only special feature is that signals can be connected to them.
    read more about signal and slots http://doc.trolltech.com/4.4/signalsandslots.html

  3. #3
    Join Date
    Apr 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: private slots ??

    Since slots are normal member functions, they follow the normal C++ rules when called directly. However, as slots, they can be invoked by any component, regardless of its access level, via a signal-slot connection. This means that a signal emitted from an instance of an arbitrary class can cause a private slot to be invoked in an instance of an unrelated class.
    "A fool can ask More questions that a wise man cannot answer"
    /home/nithyanair/Pics/image.jpg

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: private slots ??

    Quote Originally Posted by Nithya View Post
    This means that a signal emitted from an instance of an arbitrary class can cause a private slot to be invoked in an instance of an unrelated class.
    i was confused with the same thing..in my case the slot is private and i am calling it from a different class i.e the base class of the class in which the slot is ...i was surprised to see that slot being private is also visible to the base class..anyway thnks...but still

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: private slots ??

    can you show the code?

  6. #6
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: private slots ??

    Qt Code:
    1. #include "Control.h"
    2. #include <QGraphicsScene>
    3.  
    4. class MainScene:public QGraphicsScene
    5. {
    6. Q_OBJECT
    7. public:
    8. Control *contrl;
    9. MainScene();
    10. virtual ~MainScene();
    11.  
    12. };
    13.  
    14. MainScene::MainScene()
    15. {
    16. ..
    17. connect(contrl,SIGNAL(acceptButtonConnected()),contrl,SLOT(clickAcceptButton()));
    18. ..
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class Control:public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. Control();
    6. virtual ~Control();
    7.  
    8. private slots:
    9. void clickAcceptButton();
    10. signals:
    11. void acceptButtonClicked();
    12. };
    13.  
    14. void Control::clickAcceptButton()
    15. {
    16. emit this->acceptButtonClicked();
    17. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: private slots ??

    of course this slot will work, because you connect signal from control with slot which is located in control.
    try to call
    Qt Code:
    1. control->clickAcceptButton()
    To copy to clipboard, switch view to plain text mode 
    in mainWindow and you get error.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: private slots ??

    Remember that sections "private", "public" and "protected" are meaningful only during compilation - it is the compiler who decides whether one can access a particular method or field or not. But signal-slot connections are performed during runtime by the meta object system and are always called by the receiver object itself, so it will never violate a private slot. Bottom line - slots are private when called as regular methods but always public when referenced by QMetaObject::invokeMethod().

Similar Threads

  1. Replies: 12
    Last Post: 23rd June 2008, 08:05
  2. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 17:38
  3. We'll need a QT Jambi section!
    By GreyGeek in forum General Discussion
    Replies: 23
    Last Post: 30th September 2006, 00:38
  4. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28

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.