Search code examples
qt4signals-slotsslot

Error 'no such slot' qt


I am trying to connect two widgets through the signals/slots option but I keep getting this error that 'no such slot' exists. The fact is that while writing the program I used Ctrl + Space just to be sure I don't make any typos.

so I have one widget:

renderArea.h


    class renderArea : public QGraphicsView
    {
        Q_OBJECT
    public:
        renderArea(QWidget *parent = 0);

    void addClothoid(float length, float startCurvature, float endCurvature);

    signals:
        void sendData(float length, float startCurvature, float endCurvature);

    };

renderArea.cpp


    void renderArea::addClothoid(float length, float startCurvature, float endCurvature)
    {
        ...

            emit sendData(length, startCurvature, endCurvature);
        }
    }

the 2nd widget:

tableViewList.h


    class TableViewList: public QTableView
    {
        Q_OBJECT

    public:
        TableViewList(QWidget* parent = 0);

    protected slots:
        void onClothoidAdded(float length, float startCurvature, float endCurvature);
    };

tableViewList.cpp


    void TableViewList::onClothoidAdded(float length, float startCurvature, float endCurvature)
    {

    ...
    }

and the main widget:

renderingwidget.cpp where i connect the 2 above:


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

    connect(ui->graphicsView, SIGNAL(sendData(float,float,float)), ui->clothoidTable,
                SLOT(onClothoidAdded(float,float,float)));
    }

the ui->graphicsView has been promoted to renderArea and the ui->clothoidTable to the TableViewList.

So why could this error be appearing?


Solution

  • Did you re-generate your project files after adding the signal/slots to the class? Depending on your build system this is necessary to make things work.

    Qt needs to pre-process the class headers (it does not scan in cpp files) to generate the additional code that implements the signal/slot behaviour (for signal/slots it's using the MOC compiler). If Qt is not aware that class X contains a signal or slot it will just not generate the meta information for that class.

    By re-generating the project files/Make file Qt will scan all files again and generate the necessary commands for the MOC compiler.