Qt’s signal and slot mechanism works fine when you have events that occur in one component and need to be handled by one or more other components.
My situation is that an event can occur in either of two classes and it needs to be handled by each of those classes (as well as by a couple of others). For example, suppose that I’m writing a modal text editor. The mode can be changed by the user (by pressing a button on a toolbar) or by the application (when a new file is opened). I might have
// Toolbar.h
signals:
void user_changed_mode(EditingMode new_mode);
// connected to AppController::user_changed_mode
public slots:
void mode_changed(EditingMode new_mode);
// AppController.h
signals:
void mode_changed(EditingMode new_mode);
// connected to Toolbar::mode_changed
public slots:
void user_changed_mode(EditingMode new_mode);
It just seems awkward to me to have two signals that convey the same information but which have different names (and likewise for the slots). Is there a simple way to use the signals and slots mechanism when the same event can originate from multiple places?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire