expected primary expression before ',' token
-
@Axel-Spoerl
Hello Axel !
I hope this message finds you in good health and good spirits !Recently I was exploring the
connect()
method of the QObject class to connect signals-and-slots.But I'm getting this error:
expected primary expression before ',' token
.firstselfcodedqobjectclass.h
firstselfcodedqobjectclass.cpp
secondselfcodedqobjectclass.h
secondselfcodedqobjectclass.cpp
--ERROR COMING IN THIS FILE--
Would you please look into this issue and suggest me a viable solution to it.
It would be a great help from your side Axel.
-
@Ash-V
Please paste code as text, not screenshot, so people can read/copy it.connect(FirstSetCodedObjectClass, ...)
:FirstSetCodedObjectClass
is a class butconnect()
needs an instance for the signaller, just like thethis
you are using for the slot object. Signals & slots are connected between instances of signal/slot objects.You are trying to do connections in constructor of
SecondSetCodedObjectClass
. This is usually not good, because you would have to pass an instance of signalling object to that constructor. Rather the usual place to do theconnect()
is (on the line after) where you callnew SecondSetCodedObjectClass
, which has visibility of that new slot object and the existing signal object (FirstSetCodedObjectClass *
) which you want to connect. -
@JonB , @Axel-Spoerl
Hello Jon !
Thanks for your valuable reply.Could you please tell me the exact scenarios when I need to associate a data member with a Q_PROPERTY ?
I had thought that the Q_PROPERTY is for using the signals-and-slots mechanism. But it turns out from the above code that we can use it without necessarily having any Q_PROPERTY.
This is the documentation I have referred to.
-
@Ash-V
Q_PROPERTY macros are used to expose a property (at least a getter, possibly also a setter and a notification signal) to QML. You don't need it, if you do C++ only.Regarding the connect statement, @JonB has already nailed it.
The constructor ofSecondSelfCodedQObjectClass
doesn't know of any living instance ofFirstSelfCodedQObjectClass
. You have to create one, or pass it as an argument to the constructor.
Assuming thatFirstSelfCodedQObjectClass *first
contains a valid pointer, the connect statement would beconnect(first, &FirstSelfCodedQObjectClass::name1Changed, this, &SecondSelfCodedQObjectClass::onName1Changed)
-
@Axel-Spoerl
Thanks Axel !Thank you very much for your valuable reply !
-
-