PDA

View Full Version : dynamic signal connecting



donglebob
18th November 2008, 07:34
Hi,

I have two kind of classes. I use them for dynamically creating of objects at runtime.
The first one is a QWidget template for the GUI (which holds many widgets), the second one is a simple object(which holds the whole logic/functionality).

After creating this pair dynamically at runtime I want to connect each signal from classA to the slots of classB and vise versa.
It is possible that I create many instances of these two classes ( = many pair connections)!

Pair1ClassA <----->Pair1ClassB
Pair2ClassA<------>Pair2ClassB .... etc..

When the user clicks sth. on Pair1ClassAInstance the slot of Pair1ClassBInstance must be called and the same with the other instances...

Do I need to use the "Dynamic signals and slots" described here
http://doc.trolltech.com/qq/qq16-dynamicqobject.html ?

Or is there another, better workaround?

Something like:
Connecting two objects and storing this connection somewhere and after that connecting another pair...etc...

Edit:
The signals are availalbe in the Classes( no need to create them at runtime).
The slots too...just connecting at runtime...

wysota
18th November 2008, 07:41
Can't you use connect()?

donglebob
18th November 2008, 09:10
Can't you use connect()?

I tried it but somehow its not working when I create a second pair.

With the first created pair the connection works...I click sth on the gui..the object of ClassB receives it. After that It emits a "IT WORKS!" back to the GUI. Fine!

But when i create a second pair and connect them the same way the problem appears!
I click on the first-pairs GUI (QWidget) on the same button like before, the message "IT WORKS!" doesnt appear on the screen of "first-pair". It appears on the newly created one "second pair".

While connecting I checked the adresses of both. They are different!

What could be the problem?

wysota
18th November 2008, 10:44
Can we see some code?

donglebob
19th November 2008, 09:58
problem is solved now.
i made a stupid mistake while setting the information at the destination widget.