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?
-
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
-
Use
qDebug
in place of cout to see if you have a better result.