Results 1 to 5 of 5

Thread: Signal from QList Object to Slot from parent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Location
    Germany
    Posts
    6
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Signal from QList Object to Slot from parent

    I want to relay/concatenate a signal from an object I put into a QList to its parent to trigger a redraw of the parent object. But where to put the connect()?
    Qt Code:
    1. void Desktop::addTray(Tray tray) {
    2. trayList.append(tray);
    3. }
    4.  
    5. void Tray::setColor(int number, QColor color) {
    6. pointList[number].setColor(color);
    7. emit dataChanged();
    8. }
    To copy to clipboard, switch view to plain text mode 
    If I append a new tray object to the desktop I copy the object not a pointer to it. So If I would write the connect() after line 2, I wouldn’t connect to the object within the trayList.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal from QList Object to Slot from parent

    In order for Tray to have slots, it must be derived from QObject. If you tried to compile your example you would get an error as QObject-derived classes are non-copiable. What you need to do is store pointers to the Tray objects in the list and manage the memory of course.

Similar Threads

  1. SIGNAL/SLOT - Object scope?
    By StarShaper in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2012, 13:35
  2. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  3. Signal to specific object slot
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 27th December 2007, 15:51
  4. Signal-Slot, object instances
    By ct in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 19:08
  5. queued signal/slot connection with QList<int>
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 14:32

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.