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

    Question A list for storing member functions/slots?

    I apologize before hand for asking what I am sure is a very noobish question, but after looking around google for hours, I just can't figure out how to find an answer to my question, nor where to start looking in c++ documentation. My suspicion is that it has to do with my ignorance towards function pointers.

    Now, something like this makes sense to me:

    .h snippet
    Qt Code:
    1. QList<QToolButton *> *list_Button;
    2. QToolButton *card_AbandonedMine;
    To copy to clipboard, switch view to plain text mode 

    .cpp snippet
    Qt Code:
    1. card_AbandonedMine=new QToolButton;
    2. list_Button->append(card_AbandonedMine);
    To copy to clipboard, switch view to plain text mode 

    which I might make a loop like this:
    Qt Code:
    1. void DominionLinux::createCards()
    2. {
    3. for( int i = 0; i < list.size(); i++ )
    4. {
    5. list_Button->at(i)->setCheckable(true);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    That all works perfectly, and my hope is that I can also add function slots into this. The reason I can't use just one type of function, is because each slot has unique arguments.

    Now as far as creating some sort of list, I have tried applying the same principle to a member function/slot, but the closest I have come is for my program to run, but then unexpectantly crash. I went in with basically the same mindset:

    .h snippet
    Qt Code:
    1. QList<void *> *list_Slots;
    2. private slot:
    3. void *SLOTcard_AbandonedMine(bool Checked=false, bool matchOpponent=false);;
    To copy to clipboard, switch view to plain text mode 

    .cpp snippet
    Qt Code:
    1. void* DominionLinux::SLOTcard_AbandonedMine(bool Checked, bool TryMatchOpponent)
    2. {
    3. if (Checked == true)
    4. {
    5. ui->verticalLayout_Enabled->addWidget(card_AbandonedMine);
    6. }
    7. else if (Checked == false)
    8. {
    9. ui->verticalLayout_Disabled->addWidget(card_AbandonedMine);
    10. }
    11.  
    12. }
    13.  
    14. void DominionLinux::createList()
    15. {
    16. connect(card_AbandonedMine,SIGNAL(toggled(bool)), this, SLOT(SLOTcard_AbandonedMine(bool)));
    17. list_Slots->append(SLOTcard_AbandonedMine(false,false)); // If I disable this line, my program will work fine
    18. }
    To copy to clipboard, switch view to plain text mode 

    And it stops with this message:
    The inferior stopped because it received a signal from the Operating System.

    Signal name :
    SIGSEGV
    Signal meaning :
    Segmentation fault
    and this is the output
    g++ -o DominionLinux main.o DominionLinux.o qrc_cards.o moc_DominionLinux.o -lQt5Widgets -L/usr/lib/i386-linux-gnu -lQt5Network -lQt5Gui -lQt5Core -lGL -lpthread
    { test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'DominionLinux' && test -f DominionLinux.gdb-index && objcopy --add-section '.gdb_index=DominionLinux.gdb-index' --set-section-flags '.gdb_index=readonly' 'DominionLinux' 'DominionLinux' && rm -f DominionLinux.gdb-index || true
    08:08:12: The process "/usr/bin/make" exited normally.
    08:08:13: Elapsed time: 00:07.
    All I really want is just a very base and simple example of how to make some sort of list for a function/ member function/ slot (if there is a difference), so I can call it in an iterator loop.

    Hope this made sense~ Thanks in advance.
    Last edited by Akiva; 14th September 2013 at 17:55. Reason: Fixed Typo

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.