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
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

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

    Ha, you are right about a few things there, especially about having to add all all these to a list partially defeating the purpose of such a loop. Despite this, we have our reasons to do this. One such reason is to easily change the signal and perhaps add some more later. For what its worth, here is our: project https://launchpad.net/dominion.linux

    So you were quite on target with the board game suspicion.

    Anyway, I will look at the Signal Mapper for sure; There is always so much to learn!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    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.

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

    Akiva (15th September 2013)

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

    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,
    _

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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, 07:37
  2. how to document classes and member functions?
    By jackal in forum Qt Programming
    Replies: 15
    Last Post: 9th April 2011, 22:02
  3. Replies: 1
    Last Post: 16th March 2011, 08:10
  4. Pointers to Member Functions
    By Doug Broadwell in forum General Programming
    Replies: 8
    Last Post: 15th May 2007, 23:08
  5. emiting signals from const member functions !?
    By sunil.thaha in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2006, 11: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.