[SOLVED] Signal from QList Object to Slot from parent
-
wrote on 5 Apr 2012, 05:26 last edited by
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()?
@
void Desktop::addTray(Tray tray) {
trayList.append(tray);
}void Tray::setColor(int number, QColor color) {
pointList[number].setColor(color);
emit dataChanged();
}
@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.
-
wrote on 5 Apr 2012, 11:45 last edited by
since Tray is QObject subclass, "it can't be copied":http://qt-project.org/doc/qt-4.8/qobject.html#no-copy-constructor-or-assignment-operator
when you connect, you connect with the original object you created -
wrote on 5 Apr 2012, 12:15 last edited by
You're right.. I didn't inherit from QObject. I have to change my QList and store pointers, not objects.
But how can I prevent that the objects get deleted or freed?
The Tray-Objects where created dynamically while parsing a file. If the parser function is exited, every Tray object will be deleted or freed.
How can I prevent them from deletion? I thought on "static" but I want to delete the Tray objects when the QList gets cleared which would be possible with static declaration. -
wrote on 5 Apr 2012, 12:25 last edited by
well this is up to you
but you can also make the function using references, addTray(Tray &trayObject), this also will work -
wrote on 5 Apr 2012, 12:34 last edited by
Oh, you're fast! I edited my last post
-
wrote on 5 Apr 2012, 12:46 last edited by
create your objects on the heap (using new) not on the stack, this way you have to take care of deleting them and they won't be destroyed when the scope they were created in is closed.
-
wrote on 5 Apr 2012, 13:00 last edited by
OK thanks, I will rewrite my code and try to put the Trays on the heap and save pointers them in the trayList
6/7