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?
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.
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.
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.
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
Code:
connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
Its not giving me any errors but its not calling the write_data function either.
what am I doing wrong?
Re: emitting and catching signals
are you sure that receiving_finished signal is emitted? put qDebug in code where you emits this signal.
Re: emitting and catching signals
It would be easier to detect the problem if you would provide more code.
Re: emitting and catching signals
Code:
void api_request::parse_read_alldata()
{
.......
emit receiving_finished();
}//this is the classA function where i am emitting the signal
connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
//This is present in the mainclass's constructor which has a instance of classB_object but no classA instance.
void write_data()
{
qDebug() << "in write data";
}//this is the actual function that needs to be called and is present in classB.
Re: emitting and catching signals
Quote:
Originally Posted by
srohit24
Code:
connect(classA_object,SIGNAL(receiving_finished()), classB_object, SLOT(write_data()));
//This is present in the mainclass's constructor which has a instance of classB_object but no classA instance.
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?
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
Code:
connect(classA_object,SIGNAL(receiving_finished()), this, SLOT(write_data()));
QObject::connect: Cannot
connect (null)::receiving_finished() to classB
::write_data()
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.
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?
Re: emitting and catching signals
this message says another
Quote:
QObject::connect: Cannot connect (null)::receiving_finished() to classB::write_data()