I have a problem regarding connect()
method, non of these below calls work:
connect(tutorial->back, SIGNAL(clicked()), this, SLOT(exit_button_clicked()));
connect(tutorial->back, &QPushButton::clicked(), this, &MyMainWindow::exit_button_clicked());
The first one does not call exit_button_clicked()
and the second one tells me that clicked()
must be static(in Clion) and does not compile .back
is an QPushButton
and tutorial
is an custom QWidget
class. It is important to implement this method by calling custom function (for further use). Can anyone show me the right way to implement this??
the problem was with my CMakeLists.txt
, I added set(CMAKE_AUTOMOC ON)
and Q_Object
macro to my classes and it works fine now.
I presume, your exit_button_clicked()
is declared as a private or public function (not as a slot). Qt custom signals and slots have to be declared in a proper way. For example, you have your class Tutorial:
class Tutorial : QWidget {
Q_OBJECT
// Your class members go here.
// Add this slot declaration:
private slots:
void exit_button_clicked();
}
(Note the slots
keyword next to the private
).
Slots can also be public or protected, as you wish.