Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Connecting a QPushButton and a function
Forum Updated to NodeBB v4.3 + New Features

[Solved] Connecting a QPushButton and a function

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 18.6k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    I'm creating a QPushButton, putting it on the form and then connecting it so that when it gets clicked, a function is called. This is what I have in the .h file:
    @
    private:
    QPushButton *manAutoButton;

    private slots:
    void on_manAutoButton_clicked();
    @
    And this is what's in the .cpp file:
    @
    manAutoButton = new QPushButton(this);
    manAutoButton->resize(84, 84);
    manAutoButton->move(629, 270);
    connect(manAutoButton, SIGNAL(clicked()), this, SLOT(on_manAutoButton_clicked()));
    @
    When the app runs, everything is fine. The function gets called whenever I click the manAutoButton. The only thing is that I get the following message in the run window: "QMetaObject::connectSlotsByName: No matching signal for on_manAutoButton_clicked()". What am I doing wrong?

    EDIT: moved to General, peppe

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HuXiKa
      wrote on last edited by
      #2

      You have to create the on_manAutoButton_clicked() function in your .cpp file.

      If you can find faults of spelling in the text above, you can keep them.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3

        Yes, it was already in there. For completeness, this is it:
        @
        void MonitorWindow::on_manAutoButton_clicked()
        {
        if(mode == Auto)
        {
        mode = Manual;
        ui->label_28->setText("MAN");
        manAutoButton->setIcon(QIcon(QPixmap(":/MonitorWindowPix/Automatic1.png")));
        }
        }
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RazrFalcon
          wrote on last edited by
          #4

          Try to remove on_ from slot name.

          @private slots:
          void manAutoButton_clicked();

          ...

          connect(manAutoButton, SIGNAL(clicked()), this, SLOT(manAutoButton_clicked()));

          ...

          void MonitorWindow::manAutoButton_clicked()
          {@

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Endless
            wrote on last edited by
            #5

            Thanks - that did it. I guess the buttons that are placed on Designer UI forms are automatically connected to the on_buttonname_clicked functions, but creating your own functions in that format creates some confusion.

            1 Reply Last reply
            0

            • Login

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