PDA

View Full Version : Communication between two QDialog windows



omci
13th September 2009, 10:45
Hi;

I am looking for a way one QDialog can communicate to another QDialog or QMainWindow. What is the best, most secure and easiest way to achieve that?
In general I am looking one QDialog to send a string to another, and more specific I am looking how to signal a combo box to be updated when table inside a database is modified by another QDialog.

Thank you in advance!
Luka

Boron
13th September 2009, 11:11
The usual Qt way :): Use signals and slots.

Maybe the dialogs must not be modal or they won't update when sending the signal from dialog 1 to dialog 2.

omci
13th September 2009, 13:23
where do I put the
connect(Object1, signal2, Object2, slot2) code? In dialog_1 or dialog2? I put it in dialog_1, but now i do not how to connect to Object2, that is in dialog_2...

Regards; Luka

Boron
13th September 2009, 14:00
Put the connect-code "outside" both dialogs, to where the dialogs are created.
dialog_1 = new Dialog_1();
dialog_2 = new Dialog_2();
connect( dialog_1, SIGNAL(yourSignal(QString), dialog_2, SLOT(yourSlot(QString)) );
// Show the two dialogs here
I'm not sure if this work, but I would try it.

omci
13th September 2009, 15:40
Thanks, that worked perfectly. I can put the code connect in dialog_1 where I call dialog_2 and the connection works like a charm. And now I understand signals and slots mechanism a bit better.
Regards, Luka