Results 1 to 7 of 7

Thread: how to check if a signal in emited or not??

  1. #1
    Join Date
    Oct 2009
    Posts
    105
    Thanked 4 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default how to check if a signal in emited or not??

    Hi Every one,
    in .h file, i defined a signal like
    Qt Code:
    1. signals:
    2. void mySig(arg list);
    To copy to clipboard, switch view to plain text mode 
    -- assume it in a.h

    in .cpp file inside a method i'm emitting the signal like
    Qt Code:
    1. emit mySig(arg);
    To copy to clipboard, switch view to plain text mode 

    in another file, b.h
    i've a slot
    Qt Code:
    1. void mySlot(arg list same as mySig);
    To copy to clipboard, switch view to plain text mode 

    and inside b file constructor i'm connecting this mySig to mySlot.

    How ll i ckeck that if that signal is emited or not? plz help.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to check if a signal in emited or not??

    add qDebug in that place where you emit a signal.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to check if a signal in emited or not??

    i do not really understand what you mean, but if you only want to check if you code works,
    type "qDebug() << "signal/slot works"; (or what ever) and run your code to test... you'll see if the signal and slot are really connected

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to check if a signal in emited or not??

    Or just put a breakpoint on the signal and run the code. If the breakpoint is hit, the signal works.

  5. #5
    Join Date
    Oct 2009
    Posts
    105
    Thanked 4 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to check if a signal in emited or not??

    Quote Originally Posted by spirit View Post
    add qDebug in that place where you emit a signal.
    Thank you spirit for the reply. Actually i've declare the signal in .h but didn't define it in .cpp file.
    Qt Code:
    1. a.h
    2. a();
    3. ~a()
    4. function();
    5. signal:
    6. void mySig(arg);// signal return type is void
    To copy to clipboard, switch view to plain text mode 

    and inside a function
    Qt Code:
    1. a.cpp
    2. function()
    3. {
    4. ....
    5. ...
    6. qDebug()<<"checking mySig";
    7. emit mySig(arg);
    8. qDebug()<<"mySig executed";
    9. }
    To copy to clipboard, switch view to plain text mode 

    But is this the right way???

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to check if a signal in emited or not??

    actually, you don't need to define signals in cpp, because moc do it for you.
    this code is ok
    Qt Code:
    1. a.cpp
    2. function()
    3. {
    4. ....
    5. ...
    6. qDebug()<<"checking mySig";
    7. emit mySig(arg);
    8. qDebug()<<"mySig executed";
    9. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Oct 2009
    Posts
    105
    Thanked 4 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to check if a signal in emited or not??

    Quote Originally Posted by spirit View Post
    actually, you don't need to define signals in cpp, because moc do it for you.
    this code is ok
    Qt Code:
    1. a.cpp
    2. function()
    3. {
    4. ....
    5. ...
    6. qDebug()<<"checking mySig";
    7. emit mySig(arg);
    8. qDebug()<<"mySig executed";
    9. }
    To copy to clipboard, switch view to plain text mode 
    Thank you very much. and 1 more question. if i'm emitting the signal in a.cpp,
    and in b.cpp

    Qt Code:
    1. connect(a.obj, SIGNAL(mySig(arg)),this, SLOT(mySlot(arg)));
    To copy to clipboard, switch view to plain text mode 

    where mySlot(arg), is a public slot in b.h
    Is this rightway to connect Signal and slot belongs from different class?
    Last edited by sudhansu; 14th December 2009 at 08:58.

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  4. check box and signal
    By mickey in forum Newbie
    Replies: 7
    Last Post: 10th November 2007, 14:21

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.