Object::connect: No such slot QTreeWidget::on_toolButton_clicked()



  • I found similar questions in the forum, but was not sure if my case is exactly the same.

    My Code:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    public slots:
    void on_toolButton_clicked();

    };

    #endif // MAINWINDOW_H
    }@

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QObject::connect(ui->toolButton,SIGNAL(clicked()),ui->treeWidget,SLOT(on_toolButton_clicked()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_toolButton_clicked()
    {
    ui->treeWidget->setUpdatesEnabled(true);
    ui->treeWidget->setColumnCount(3);
    ui->treeWidget->update();
    @

    @#include <QtGui/QApplication>
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    int main(int argc, char *argv[])
    {

    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    return a.exec&#40;&#41;;
    

    }
    @

    My application works and the third column in the tree widget is set after the button is clicked, but I get this annoying message Object::connect: No such slot QTreeWidget::on_toolButton_clicked() .
    Why?


  • Moderators

    welcome to devnet

    Your public slot is a method in MainWindow and not in QTreeWidget as you claim.

    If I understand your code correctly, this should avoid the error message, but may not do what you intend.
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    connect(ui->toolButton,SIGNAL(clicked()), this, SLOT(on_toolButton_clicked()));
    }
    @



  • Yes, the error message is no longer there.
    Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.