example_c3.cpp 755 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdio.h>
  2. #include "example_c3.h"
  3. A::A(QObject *parent = 0, const char *name = 0)
  4. : QObject(parent, name)
  5. {
  6. }
  7. void A::emitSigA()
  8. {
  9. printf("A: emitting sigA!\n");
  10. emit sigA();
  11. }
  12. void A::gotSigB()
  13. {
  14. printf("A: got sigB!\n");
  15. }
  16. B::B(QObject *parent = 0, const char *name = 0)
  17. : QObject(parent, name)
  18. {
  19. }
  20. void B::emitSigB()
  21. {
  22. printf("B: emitting sigB!\n");
  23. emit sigB();
  24. }
  25. void B::gotSigA()
  26. {
  27. printf("B: got sigA!\n");
  28. }
  29. int main(void)
  30. {
  31. A *a = new A(0, "class a");
  32. B *b = new B(0, "class b");
  33. QObject::connect(a, SIGNAL(sigA()), b, SLOT(gotSigA()));
  34. QObject::connect(b, SIGNAL(sigB()), a, SLOT(gotSigB()));
  35. a->emitSigA();
  36. b->emitSigB();
  37. delete b;
  38. delete a;
  39. return 0;
  40. }