Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Signal and Slots are not Working in my project
Qt 6.11 is out! See what's new in the release blog

Signal and Slots are not Working in my project

Scheduled Pinned Locked Moved Solved C++ Gurus
2 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shaharyaar
    wrote on last edited by Shaharyaar
    #1

    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.
    alt text

    alt text

    .cpp file

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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 QPushButton doesn't have a method (signal) named sayHello. It's a method (signal) in MainWindow class.

      QPushButton has 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 sayHello when the button "Hi" is pressed and then in response to that you want to call replyHi you 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
      
      1 Reply Last reply
      6

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved