signal/slot between two different classes
- 
hello , I want to send variable from class A to class B using signal and slots . 
 who can told me how .
 thank you@dziko147 said in signal/slot between two different classes: who can told me how Documentation can: https://doc.qt.io/qt-5/signalsandslots.html 
- 
@jsulm be sure that I tried to recover on my own . if you can't/do not want help me ,please ignore this topic :) @dziko147 said in signal/slot between two different classes: be sure that I tried to recover on my own Then please show what you tried and say what went wrong if you want to get meaningful help... 
- 
@dziko147 said in signal/slot between two different classes: be sure that I tried to recover on my own Then please show what you tried and say what went wrong if you want to get meaningful help... @jsulm ok I tried this actually signals: void canDeviceChanged(int value);connect(this, SIGNAL(canDeviceChanged(int value )),&back, SLOT(statuspican(int value))); if (m_canDevice) emit canDeviceChanged(1);in backend.h public slots: void statuspican(int value);in backend.cpp void Backend::statuspican(int value) { qDebug() << "from Mainwindow :" << value; }
- 
@jsulm ok I tried this actually signals: void canDeviceChanged(int value);connect(this, SIGNAL(canDeviceChanged(int value )),&back, SLOT(statuspican(int value))); if (m_canDevice) emit canDeviceChanged(1);in backend.h public slots: void statuspican(int value);in backend.cpp void Backend::statuspican(int value) { qDebug() << "from Mainwindow :" << value; }@dziko147 said in signal/slot between two different classes: connect(this, SIGNAL(canDeviceChanged(int value )),&back, SLOT(statuspican2(int value))); Have you read the link a give you at least 5 times? 
 This can not work ==> https://doc.qt.io/qt-5/qobject.html#connectEDIT 
 What isstatuspican2?
 According to your code, the slot name isstatuspican
- 
@jsulm ok I tried this actually signals: void canDeviceChanged(int value);connect(this, SIGNAL(canDeviceChanged(int value )),&back, SLOT(statuspican(int value))); if (m_canDevice) emit canDeviceChanged(1);in backend.h public slots: void statuspican(int value);in backend.cpp void Backend::statuspican(int value) { qDebug() << "from Mainwindow :" << value; }@dziko147 said in signal/slot between two different classes: connect(this, SIGNAL(canDeviceChanged(int value )),&back, SLOT(statuspican2(int value))); Remove "value". Old style connect does only contain the parameter type, not its name. 
 But you should really switch to new Qt5 connect syntax - if you then do something wrong you will get a compiler error. With old style connect you only get a runtime warning if connect fails.
- 
@dziko147 Did you read what I and @KroMignon wrote? 
- 
@dziko147 said in signal/slot between two different classes: so logically it should works , there is no syntax error ! ? Are you jocking? Nothing is correct: - the slot name is wrong
- the SIGNAL()syntax is wrong ==> only signal signature means: signal name and parameter types
- the SLOT()syntax is wrong ==> only slot signature means: slot name and parameter types
 
- 
@dziko147 said in signal/slot between two different classes: so logically it should works , there is no syntax error ! ? Are you jocking? Nothing is correct: - the slot name is wrong
- the SIGNAL()syntax is wrong ==> only signal signature means: signal name and parameter types
- the SLOT()syntax is wrong ==> only slot signature means: slot name and parameter types
 @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 . @jsulm already told you what's wrong and you should switch over to the new signal/slot syntax so you get proper compile time errors instead during runtime. 
- 
@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 ? 
 


