Results 1 to 2 of 2

Thread: Can I define "anonnymous" slots somehow?

  1. #1
    Join Date
    Nov 2009
    Posts
    10
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Can I define "anonnymous" slots somehow?

    Hello, I have this class:

    Qt Code:
    1. class MyWindow : public QMainWindow {
    2. Q_OBJECT
    3.  
    4. public:
    5. MyWindow();
    6.  
    7. signals:
    8. void aspectRatioChange(AspectRatio aspectRatio);
    9.  
    10. private slots:
    11. void setAspectRatio(QAction* action);
    12.  
    13. private:
    14. struct Impl;
    15. std::auto_ptr<Impl> imp;
    16. };
    To copy to clipboard, switch view to plain text mode 

    which works alright as it is. I would like to know if I could get rid of that setAspectRatio() private slot somehow by using an "anonymous" function (callback?) in the QObject::connect() statement. My goal is to reduce as much possible the implementation details from my header files.

    Thank you

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

    Default Re: Can I define "anonnymous" slots somehow?

    I don't get it. The connect call will fail if there's no slot to call, and tell you in the output window that the slot doesn't exist.

    Perhaps you would be better with a private/public class relationship. Your internal slots go into the private class, and the public ones go into the public class. You can forward declare the private class pointer, so there's no need for its header file or definition.

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  2. Replies: 12
    Last Post: 23rd June 2008, 08:05
  3. odd double widgets
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2008, 18:18
  4. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 17:38
  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.