Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Signal and Slots are not Working in my project
Shaharyaar last edited by Shaharyaar
I am using Qt for my end semester programming project. I was making a program to understand signal and slots after watching an introductory video on youtube.
I am uploading pictures of my .ui .cpp .h files so that you guys can understand what I am trying to do.
As you can see in application output that it says "no such signal sayhello" even though I have included in my .h file. Moreover, according to the code when I press pushbutton_2 then text of pushbutton should change from "Bye" to "aaa". But such thing also doesn't happen.
I think you misunderstand how signals/slots work.
in your connect statement the first param is an object emitting a signal and the second one is a method (signal) of that object's class. Class
QPushButtondoesn't have a method (signal) named
sayHello. It's a method (signal) in
QPushButtonhas a method (signal) named
clicked(), so you can connect that. If you want to call
pushed()when the button "Hi" is clicked then you connect like this:
connect(ui->pushButton_2, &QPushButton::clicked, this, &MainWindow::pushed);
If you want the main window to emit
sayHellowhen the button "Hi" is pressed and then in response to that you want to call
replyHiyou make two connections:
connect(ui->pushButton_2, &QPushButton::clicked, this, &MainWindow::sayHello); // emits sayHello when the button is clicked connect(this, &MainWindow::sayHello, this, &MainWindow::replyHi); // calls replyHi when sayHello is emitted