In Qt, what is the most elegant way to pass data from a QDialog subclass to the component that started the dialog in the cases where you need to pass down something more complex than a boolean or an integer return code?
I'm thinking emit a custom signal from the accept()
slot but is there something else?
In the general case, if the data is fairly simple I like to create one or more custom signals and emit those as necessary. Simple or complex data, I will generally provide accessors for the data. In the complex case, then, I would connect a slot to the
accepted
signal, and get the desired information in that slot. The drawback to this is that you generally need to rely on storing a pointer to the dialog, or using thesender()
hack to figure out which object triggered the slot.QDialog has its own message loop and since it stops your application workflow, I usually use the following scheme: