Results 1 to 17 of 17

Thread: A list for storing member functions/slots?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    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?

    To me what you want to accomplish will not make your code shorter as you still have to add all those slot names to the list, but here you go:

    Qt Code:
    1. QList<const char*> slotList;
    2. slotList << SLOT(slot1());
    3. slotList << SLOT(slot2());
    4. // ...
    5.  
    6. for(int i=0; i< listOfButtons.size();++i) {
    7. connect(listOfButtons->at(i), SIGNAL(clicked()), this, slotList.at(i));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Having said that I have to admit it all makes little sense to me. I'm assuming you are programming some kind of game (possibly a board game?) and you are using all those buttons for some kind of fields or pieces. In my opinion a much better approach would be to use Graphics View or at least to use a QSignalMapper and connect all your buttons to a single slot keyed by the button id.
    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.


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

    Akiva (15th September 2013)

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.