Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot in Qt versions < Qt 5.
In order to use signals/slots the meta object compiler has to be invoked. To make this happen your class should meet the following requirements:
QObjector any other subclass (egQWidget,QPushButtonetc)Q_OBJECTmacro should be defined in the private section of the class in order to enable meta-object features such as slotsQtkeywordsslotsandsignalsin order to declare which functions should be handles by the meta compiler as slots or signalsFor more details check the corresponding documentation pages about the meta-object system and the signals & slots
Also check the
QObjectdocumentation:Edit: Since Qt 5, functors and lambda expressions can be used as slot. See
New Signal Slot Syntax in Qt 5