signal/slot between two different classes
- 
@KroMignon ok could you provide a connect implementation to solve this .
i am blocked since 3 days :/
@dziko147 said in signal/slot between two different classes:
ok could you provide a connect implementation to solve this .
i am blocked since 3 days :/Can you read?
@jsulm told you what to do:
Remove "value". Old style connect does only contain the parameter type, not its name.
And in Qt documentation:
Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG QObject::connect(scrollBar, SIGNAL(valueChanged(int value)), label, SLOT(setNum(int value))); // CORRECT QObject::connect(scrollBar, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)));I cannot believe this take 3 days to understand.
 - 
@KroMignon even i remove the "value" it doesn't works .
I didn't understand why .
No error but the application spits . - 
@KroMignon even i remove the "value" it doesn't works .
I didn't understand why .
No error but the application spits .@dziko147 said in signal/slot between two different classes:
No error but the application spits .
Why not using the debugger to find out why your application crash?
And in you connect:
connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));What is
back?
Where is it defined? - 
@KroMignon even i remove the "value" it doesn't works .
I didn't understand why .
No error but the application spits .@dziko147 Next thing to check: what does connect() call return?
qDebug() << connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));Next: did you make sure that the signal is actually emitted?
if (m_canDevice) { qDebug() << "Emit signal"; emit canDeviceChanged(1); } - 
@dziko147 Next thing to check: what does connect() call return?
qDebug() << connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));Next: did you make sure that the signal is actually emitted?
if (m_canDevice) { qDebug() << "Emit signal"; emit canDeviceChanged(1); } - 
qDebug() << connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));return true .
And the signal is emmited
Hi,
@dziko147 said in signal/slot between two different classes:
qDebug() << connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));return true .
And the signal is emmited
Where is back defined ?
Any chances that this is a function local variable that is destroyed at the end of it ? - 
Hi,
@dziko147 said in signal/slot between two different classes:
qDebug() << connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));return true .
And the signal is emmited
Where is back defined ?
Any chances that this is a function local variable that is destroyed at the end of it ? - 
The question is: where is it defined ?
 - 
That's what I suspected: back is destroyed at the end of the constructor.
 - 
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), { m_ui->setupUi(this); Backend back ; connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));@dziko147 said in signal/slot between two different classes:
{
m_ui->setupUi(this); Backend back ; connect(this, SIGNAL(canDeviceChanged(int)),&back, SLOT(statuspican(int)));I know that you are a C++/Qt beginner, but as many times written: please take time to understand C++ basics.
C++ variable scope and life-cycle is one of them:
- https://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm
 - https://www.geeksforgeeks.org/scope-of-variables-in-c/
 - there are many more available on internet
 
If you don't learn, how do you expect programming?
 - 
@KroMignon Hello
to create a global variable . Can i create Backend back; in MainWindow.h . - 
@KroMignon Hello
to create a global variable . Can i create Backend back; in MainWindow.h .@dziko147 said in signal/slot between two different classes:
to create a global variable . Can i create Backend back; in MainWindow.h .
I don't want to be pedantic, but as you seems to be very unexperimented I will try to be as clear as possible.
There is no need of a global variable at all.
For me, there are 2 clean way to do it:
- create a variable in 
main()and do all connection there. - add a class attribute from type 
BackendintoMainWindowand eventually give access to it through getter. 
My preferred way is the second.
But this is up to you. - create a variable in