Results 1 to 13 of 13

Thread: emitting and catching signals

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default emitting and catching signals

    Hi

    I have two classes called receive and write.

    What i need is , a signal is emitted in the receive class. this signal has to be caught in the write class and proceed as instructed.

    I am emitting a signal called finished_receiving after i have parsed the data I get from a website.
    I want to connect this signal to a proceed function in the write class.

    What all should i specify in the connect? how should I declare the sender and receiver objects?

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: emitting and catching signals

    Read about signals and slots in Qt Assistant or just click here as it is the link to online documentations, exactly the same which is in Assistant.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: emitting and catching signals

    I have read that. I am able to emit signals and catch them in a single class.

    I am facing problems when i need to emit and catch them in 2 different classes.

    A bit of help in the direction of the solution will be greatly helpful.

  4. #4
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: emitting and catching signals

    Your class should be instantiate somewhere. There you should add
    connect (classA, SIGNAL(signalA()), classB, SLOT(slotB()))
    same as in the same class.

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: emitting and catching signals

    The two classes are classA and classB. The main class is declared as mainclass.

    I am emitting a signal in classA. I have written the code for connect in mainclass's constructor
    I have created a instance of the classA in the mainclass. The classA action isnt related to the mainclass action.

    this is my connect signal

    Qt Code:
    1. connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
    To copy to clipboard, switch view to plain text mode 

    Its not giving me any errors but its not calling the write_data function either.

    what am I doing wrong?

  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: emitting and catching signals

    are you sure that receiving_finished signal is emitted? put qDebug in code where you emits this signal.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: emitting and catching signals

    It would be easier to detect the problem if you would provide more code.

  8. #8
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: emitting and catching signals

    Qt Code:
    1. void api_request::parse_read_alldata()
    2. {
    3. .......
    4. emit receiving_finished();
    5. }//this is the classA function where i am emitting the signal
    6.  
    7. connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
    8. //This is present in the mainclass's constructor which has a instance of classB_object but no classA instance.
    9.  
    10. void write_data()
    11. {
    12. qDebug() << "in write data";
    13. }//this is the actual function that needs to be called and is present in classB.
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: emitting and catching signals

    Quote Originally Posted by srohit24 View Post
    Qt Code:
    1. connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
    2. //This is present in the mainclass's constructor which has a instance of classB_object but no classA instance.
    To copy to clipboard, switch view to plain text mode 
    you say the "no classA instance." is present in mainclass so how are you able to connect..
    i am afraid that you need to give some more code... why not just provide a simple minimal compilable program reproducing the problem?

  10. #10
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: emitting and catching signals

    Should i place the connect command in classB's constructor to connect the signals as classB has classA's instance?

    EDIT

    I placed the connect code in the classB's constructor.The app compiled successfully but i got this in qDebug


    Qt Code:
    1. connect(classA_object,SIGNAL(receiving_finished()), this, SLOT(write_data()));
    2.  
    3. QObject::connect: Cannot connect (null)::receiving_finished() to classB::write_data()
    To copy to clipboard, switch view to plain text mode 
    Last edited by srohit24; 4th August 2009 at 05:36.

  11. #11
    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: emitting and catching signals

    classA_object is not created, i.e. classA_object == 0.
    EDIT: take a debugger in your hands and debug your programm step by step.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #12
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: emitting and catching signals

    ok. but I have created a class object and I am using it make a function call.

    how can that be null?

  13. #13
    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: emitting and catching signals

    this message says another
    QObject::connect: Cannot connect (null)::receiving_finished() to classB::write_data()
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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.