Results 1 to 4 of 4

Thread: Slot not getting called, Qt::ConnectionType, Thread

  1. #1
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Slot not getting called, Qt::ConnectionType, Thread

    I have some strange problems with one SIGNAL/SLOT.

    There is one class A::B::Class1 that emits two signals, first without argument, second with one argument.

    Qt Code:
    1. A::B::J param;
    2. emit orange(param); // Not executed
    3. emit blue();
    To copy to clipboard, switch view to plain text mode 

    In A::C::Class2 the signals and slots are connected. Both connections returns true, but only 1 Slot gets executed, that one without any parameter.

    Qt Code:
    1. void V::run()
    2. {
    3. object = new Object();
    4.  
    5. connect(object, SIGNAL(blue()), this, SLOT(blue_exec()));
    6. connect(object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)));
    7.  
    8. //...
    9.  
    10. exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    It is definately a problem with the SIGNAL.

    I just did a test with Qt::ConnectionType and a test allocating object on stack with Object object and

    Qt Code:
    1. void V::run()
    2. {
    3. Object object;
    4.  
    5. connect(&object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)));
    6.  
    7. //...
    8.  
    9. exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    It works. Same thing, if I use Qt:irectConnection.

    Qt Code:
    1. void V::run()
    2. {
    3. object = new Object();
    4.  
    5. connect(object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)), Qt::DirectConnection);
    6.  
    7. //...
    8.  
    9. exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    That doesn't make sense to me. Why the first connection gets executed, while the second does not. Both are using the same "object"?

    Last edited by StarShaper; 7th February 2012 at 04:08.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slot not getting called, Qt::ConnectionType, Thread

    Look in the output of your program for warnings like:
    Qt Code:
    1. QObject::connect: Cannot queue arguments of type 'A::B::J&'
    2. (Make sure 'A::B::J&' is registered using qRegisterMetaType().)
    To copy to clipboard, switch view to plain text mode 
    You will not be able to queue a reference though.

  3. #3
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Slot not getting called, Qt::ConnectionType, Thread

    if it is a const reference then he can to queue it, but he have to provide meta data for that type of reference.
    Not const reference requires Blocking Queued Connection.
    See:
    http://developer.qt.nokia.com/doc/qt...across-threads
    http://developer.qt.nokia.com/doc/qt...ctionType-enum
    http://developer.qt.nokia.com/doc/qt...gisterMetaType

  4. #4
    Join Date
    Jan 2012
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slot not getting called, Qt::ConnectionType, Thread

    A::B::J& works! It is registered. But the Signal only works, if object is created in the run() method with Object object;

    Read the second part of my posting.

    And it also works, if I append Qt:irectConnection.

    This is really strange!

    Must be some kind of threading issue.

    @MarekR22: I'm aware of the threading issues with Connection. But it doesn't make sense to me in my example. Both objects are from the same thread.


    Added after 11 minutes:


    Quote Originally Posted by StarShaper View Post
    A::B::J& works! It is registered. But the Signal only works, if object is created in the run() method with Object object;

    Read the second part of my posting.

    And it also works, if I append Qt:irectConnection.

    This is really strange!

    Must be some kind of threading issue.

    @MarekR22: I'm aware of the threading issues with Connection. But it doesn't make sense to me in my example. Both objects are from the same thread.
    Yes, it works also with qRegisterMetaType();

    If is is a const reference and if I do:

    Qt Code:
    1. qRegisterMetaType<A::B::J>("A::B::J");
    2. connect(object, SIGNAL(orange(const A::B::J&)), this, SLOT(orange_exec(const A::B::J&)));
    To copy to clipboard, switch view to plain text mode 
    Last edited by StarShaper; 7th February 2012 at 14:04.

Similar Threads

  1. Replies: 2
    Last Post: 26th August 2011, 08:51
  2. connect() return value
    By hojoff79 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 13:48
  3. Replies: 1
    Last Post: 19th October 2010, 05:08
  4. qdbus connect return always FALSE
    By ciberkids in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2009, 14:17
  5. connect() returns true but slot not called
    By OriginalCopy in forum Qt Programming
    Replies: 6
    Last Post: 4th November 2007, 18:54

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
  •  
Qt is a trademark of The Qt Company.