Results 1 to 17 of 17

Thread: A list for storing member functions/slots?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: A list for storing member functions/slots?

    Since each QToolButton is a QObject you already have a generic way to get/set any declared property of the button without knowing the specific class of the button: QObject::property() and QObject::setProperty(). You can access information on available properties through the QMetaObject of the QToolButton.

    If all the tool buttons belong to a single parent object then you can access them using the child list of the parent using QObject::findChildren() without necessarily maintanng a separate list.

    Have a think about how these functions might be useful to you.

  2. The following user says thank you to ChrisW67 for this useful post:

    Akiva (15th September 2013)

  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: A list for storing member functions/slots?

    Good suggestion Chris.

    Additional to that all buttons could connect to the same slot, QObject::sender() could be used to retrieve the button and then QObject:roperty() could be used to extract the respective parameters.

    Of, if all buttons have the same types of parameters but just different values, create a QToolButton subclass that has methods for those and cast QObject::sender() to that class and call the getters directly.

    Another option would be to have separate receiver objects, one for each button. Each such instance would get its individual parameters upon construction, thus not needing any in the slot.

    e.g.
    Qt Code:
    1. class ButtonReceiver : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. ButtonReceiver( /* parameter */, QObject *parent = 0);
    6.  
    7. public slots:
    8. void onButtonClicked();
    9. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QList<ButtonReceiver*> receiverList;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. for (int i = 0; i < buttonList; ++i) {
    2. connect(buttonList[i], SIGNAL(clicked()), receiverList[i], SLOT(onButtonClicked()));
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Default Re: A list for storing member functions/slots?

    I have taken a look at the code in the repository mentioned by OP. The code there contains a couple hundred of practically identical slots generated by some external python tool.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Pointer to non static member functions within the class
    By Lykurg in forum General Programming
    Replies: 3
    Last Post: 24th April 2011, 08:37
  2. how to document classes and member functions?
    By jackal in forum Qt Programming
    Replies: 15
    Last Post: 9th April 2011, 23:02
  3. Replies: 1
    Last Post: 16th March 2011, 09:10
  4. Pointers to Member Functions
    By Doug Broadwell in forum General Programming
    Replies: 8
    Last Post: 16th May 2007, 00:08
  5. emiting signals from const member functions !?
    By sunil.thaha in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2006, 12:29

Tags for this Thread

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.