My code has a strange behaviour:
I want to set a signal-slot connection. When I do not have any parameters it works fine. But when I use parameters even as as easy ones like int my connection doesn`t work. Does anybody has a clue as to why that may be?
Thank you.
This works:
Chart.h
void signalForUI();
Chart.cpp
emit signalForUI();
Userinterface.h
public slots:
void UI_schreibtWas();
Userinterface.cpp
connect( ui.Diagram , SIGNAL( signalForUI() ),
this ,SLOT (UI_schreibtWas())) ;
...
void UserInterface::UI_schreibtWas()
{ qDebug() << "ich schreibe was- ohne "; }
This doesn`t:
Chart.h
void signalForUI(const int &X_send);
Chart.cpp
emit signalForUI(5);
Userinterface.h
public slots:
void UI_schreibtWas(const int &X_send);
Userinterface.cpp
connect( ui.Diagram , SIGNAL( signalForUI(const int &X_send) ),
this ,SLOT (UI_schreibtWas(const int &X_send))) ;
...
void UserInterface::UI_schreibtWas(const int &X_send)
{ qDebug() << "ich schreibe was - int "; }
You're not supposed to pass parameter names into signal/slot definitions for connect
.
connect(ui.Diagram, SIGNAL(signalForUI(const int&)),
this, SLOT(UI_schreibtWas(const int&)));
But you should use the Qt 5 syntax for connect, which does not use macros and allows you to catch such errors at compile time:
connect(ui.Diagram, &DiagramClass::signalForUI, this, &ThisClass::UI_schreibtWas)
Replace DiagramClass
and ThisClass
with appropriate class names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.