error connecting signal to slot in custom class
-
Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:
connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));mapChart
class mapChart : public QChart { public slots: void pointClicked(const QPointF &point); };However when I do so I get the error
QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF)which I don't understand as my chart4Map is a mapChart instance -
Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:
connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));mapChart
class mapChart : public QChart { public slots: void pointClicked(const QPointF &point); };However when I do so I get the error
QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF)which I don't understand as my chart4Map is a mapChart instance -
Hello, I am trying to connect a signal between a series in a custom chart class to a slot in said chart class like so:
connect(series, SIGNAL(clicked(QPointF)), chart4Map, SLOT(pointClicked(QPointF)));mapChart
class mapChart : public QChart { public slots: void pointClicked(const QPointF &point); };However when I do so I get the error
QObject::connect: No such slot QtCharts::QChart::pointClicked(QPointF)which I don't understand as my chart4Map is a mapChart instance -
The mapChart class presented is lacking a Q_OBJECT macro.
Also, have you ensured thatmochas run over the header declaring mapChart?@ChrisW67 said in error connecting signal to slot in custom class:
The mapChart class presented is lacking a Q_OBJECT macro.
This is true, but as far as I know
Q_OBJECTis not required for slots, only for signals?Am I not right that the
QPointFwill not matchconst QPointF &point, and that is the error here? [UPDATE Oh, @J-Hilk says Qt4 will match these similar-but-different signatures, so maybe I am wrong, and it is indeed somehow theQ_OBJECTmissing for Qt4, sorry if my attempts at answering have been wrong, I have learned something about Qt4 now! See also https://forum.qt.io/topic/115188/do-i-need-to-use-the-q_object-macro-if-i-only-use-slots]@J-Hilk said in error connecting signal to slot in custom class:
@Deneguil you're using old(Qt4) signal slot syntax, so your class 100% requires Q_OBJECT macro to work.
Ah, I did not know that requirement! I don't think it's mandatory for a slot in new style, at least? One more reason for using new-style if not bound to Qt4!
-
@ChrisW67 said in error connecting signal to slot in custom class:
The mapChart class presented is lacking a Q_OBJECT macro.
This is true, but as far as I know
Q_OBJECTis not required for slots, only for signals?Am I not right that the
QPointFwill not matchconst QPointF &point, and that is the error here? [UPDATE Oh, @J-Hilk says Qt4 will match these similar-but-different signatures, so maybe I am wrong, and it is indeed somehow theQ_OBJECTmissing for Qt4, sorry if my attempts at answering have been wrong, I have learned something about Qt4 now! See also https://forum.qt.io/topic/115188/do-i-need-to-use-the-q_object-macro-if-i-only-use-slots]@J-Hilk said in error connecting signal to slot in custom class:
@Deneguil you're using old(Qt4) signal slot syntax, so your class 100% requires Q_OBJECT macro to work.
Ah, I did not know that requirement! I don't think it's mandatory for a slot in new style, at least? One more reason for using new-style if not bound to Qt4!
@JonB said in error connecting signal to slot in custom class:
I don't think it's mandatory for a slot in new style, at least?
you would be correct, the class containing the signal still requires it (I think)
-
@Deneguil
Since your slot signature parameter isconst QPointF &pointit won't match the plainQPointFin yourSLOT().Why don't you use "new" (actually very old now!) signal/slot syntax, instead of
SIGNAL/SLOT(), it gives more help on these errors?@JonB said in error connecting signal to slot in custom class:
Since your slot signature parameter is
const QPointF &pointit won't match the plainQPointFin yourSLOT().I tried fixing the slot signature and adding the Q_OBJECT macro to my class as well and this time I got
QObject::connect: No such signal QtCharts::QScatterSeries::clicked(const QPointF &point)which seems weird to me since ScatterSeries should have the signal inhearited from XYSeries.Why don't you use "new" (actually very old now!) signal/slot syntax, instead of
SIGNAL/SLOT(), it gives more help on these errors?There was no other reason than I'm pretty new to Qt development and so far that was the syntax that worked for me so I didn't see a reason to change.
However after changing it toconnect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked);it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now tooThank you all for your help
-
@JonB said in error connecting signal to slot in custom class:
Since your slot signature parameter is
const QPointF &pointit won't match the plainQPointFin yourSLOT().I tried fixing the slot signature and adding the Q_OBJECT macro to my class as well and this time I got
QObject::connect: No such signal QtCharts::QScatterSeries::clicked(const QPointF &point)which seems weird to me since ScatterSeries should have the signal inhearited from XYSeries.Why don't you use "new" (actually very old now!) signal/slot syntax, instead of
SIGNAL/SLOT(), it gives more help on these errors?There was no other reason than I'm pretty new to Qt development and so far that was the syntax that worked for me so I didn't see a reason to change.
However after changing it toconnect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked);it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now tooThank you all for your help
@Deneguil said in error connecting signal to slot in custom class:
However after changing it to
connect(series, &QScatterSeries::clicked, chart4Map, &mapChart::pointClicked);it works now so I'm probably going to change every SIGNAL()/SLOT() in my code now too:) :) New style was introduced years & years ago. I know some old examples still use
SIGNAL/SLOT(), but assuming you are Qt5 onward you are really a lot better off with new style!