Results 1 to 4 of 4

Thread: Signal & Slots when pointer to the sender object has been copied

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal & Slots when pointer to the sender object has been copied

    Hi guys, Im sorry if I cannot explain properly the situation

    lets get some

    the header could be header.h

    Qt Code:
    1. class A:
    2. {
    3. signals:
    4. MySignal();
    5. };
    6.  
    7. class MainWindow
    8. {
    9. A * a:
    10.  
    11. // More things
    12. //........
    13.  
    14. };
    15.  
    16. class B
    17. {
    18. public:
    19. B(A* a);
    20. private slots:
    21. myDummySlotInB()
    22.  
    23. private:
    24. A* my_a;
    25. }
    To copy to clipboard, switch view to plain text mode 

    lets see supose that the cpp file contains
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. connect(a, SIGNAL(MySignal()), this, SLOT(dummySlot()));
    4. //......
    5. }
    6.  
    7.  
    8. B::B(A* a)
    9. {
    10. my_a = a;
    11.  
    12. connect(my_a, SIGNAL(MySignal()), this, SLOT(dummySlotInB()));
    13. }
    To copy to clipboard, switch view to plain text mode 

    Why the connection in the constructor of MainWindow is working properly, and no the connection in the constructor of B?. I just copied the pointer, so my_a is poiting to (*a) as well. Then, if the pointer a emits the signal, Why I cannot catch it in B?

    Thanks
    Last edited by locke; 30th July 2010 at 17:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Signal & Slots when pointer to the sender object has been copied

    Are you sure you have the macro Q_OBJECT in your class B. Is there any error shown when you connect?

  3. The following user says thank you to Lykurg for this useful post:

    locke (30th July 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal & Slots when pointer to the sender object has been copied

    The class B has the macro Q_OBJECT (it also send signals) and there is no compiling problem. I can execute the app but the connection in B doesnt work

  5. #4
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal & Slots when pointer to the sender object has been copied

    Solved: There was a small diference in the name of the SLOT. It lets you complile but there is no slot to catch the signal.

Similar Threads

  1. [solved] Which object type is QObject::sender()?
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 8th May 2009, 22:03
  2. Qt slots sender pointer
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2009, 13:45
  3. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 18:31
  4. static Object Vs Pointer
    By rajeshs in forum General Programming
    Replies: 4
    Last Post: 11th June 2008, 08:41
  5. Pointer to ActiveX object in QT
    By json84 in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2007, 13:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.