Solved connect the two class in signal ,slot and emit?
-
I have to class file mainwindow and updater. Now i want to sent the data from updater to mainwindow.
updater.h signals: void Ok(int x); updater.cpp void fun(){ x = 10; emit Ok(x); }
class form;
mainwindow.hprivate slots: void receive(int x); #include "updater.h" mainwindow.cpp mainwindow::mainwindow(){ updater*data = new updater(this); connect(data , &updater::Ok, this, &MainWindow::receiveOk); } void receiveOk(int x){ cout << x; }
I have done all these thing but still emit Signal not reflected inside the mainwindow.cpp file?
-
What is the question?
-
@sierdzio try to send data from form.cpp file and access the same data inside mainwindow.cpp . when i try to send data from form.cpp file emit not emit the signal to mainwindow.cpp.
-
OK, but instead of showing us code of your "form" class, you posted "updater" class.
Also, in connect statement, you connect to "receiveOk" slot, but you pasted code for "receive" slot instead.
Provide all the data and I'll try to help you. Right now I have no means of doing so.
-
Hi,
@amarism said in connect the two class in signal ,slot and emit?:
update.cpp
void fun(){
x = 10;
emit Ok(int x);
}The emit statement is wrong, it should be:
emit Ok(x);
@amarism said in connect the two class in signal ,slot and emit?:
mainwindow.cpp
connect(data , &Form::ok, this, &MainWindow::receiveOk);This won't compile as the name of the signal is wrong. It's
Ok
notok
-
@SGaist I have correct all the thing but still emit not reflected into mainwindow.cpp
-
Use
qDebug
in place of cout to see if you have a better result. -
@amarism said in connect the two class in signal ,slot and emit?:
void receiveOk(int x){
cout << x;
}Shouldn't this be:
void mianwindow::receiveOk(int x){ cout << x; }
-
@SGaist yup now i solve the issue Thank you