Nominate our 2022 Qt Champions!

No such slot error

  • Hello,

    I'm sure this must have been aked a thousend times, but all the solutions I found, where missing Q_OBJECT in the *.h files or not having set keyword slot (well and sometimes not having run the moc).

    But let's start from the beginning:
    I trying to write a small test application just for learning purposes using KDevelop, cmake and, of course, QT. :) But I'm stuck at the moment as the app claims the following:

    Object::connect: No such slot qimageview::about() in /home/jankoh/projects/qimageview/qimageview.cpp:15
    Object::connect: (sender name: 'actionAbout')
    Object::connect: (receiver name: 'MainWindow')

    Here is the code:


    #ifndef qimageview_H
    #define qimageview_H

    #include <QtGui/QMainWindow>

    #include "ui_qimageview.h"

    class qimageview : public QMainWindow, private Ui::MainWindow

    qimageview(QWidget *parent = 0);
    virtual ~qimageview();

    public slots:
    void about();

    #endif // qimageview_H


    #include "qimageview.h"

    #include <QtGui/QLabel>
    #include <QtGui/QMenu>
    #include <QtGui/QMenuBar>
    #include <QtGui/QAction>

    #include "qimageview.moc"

    qimageview::qimageview(QWidget *parent)

    connect(MainWindow::actionClose, SIGNAL( triggered() ), this, SLOT( close() ) );
    connect(MainWindow::actionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );



    void about()

    What am I missing? The moc is freshly generated...

    Thank's in advance and best regards, Jan

  • Moderators

    You do not instantiatie QMainWindow.

    Try this as the first line for constructor:
    qimageview::qimageview(QWidget *parent) : QMainWindow(parent)

    But I am not sure that is the source of the problem. Might also be the strange first argument in both connect statements.

    Well, maybe it will help. Do report regardless of the outcome :)

  • Thanks for the reply, but that change does not effect the error.

    I also changed the connect statements to read:
    connect(actionClose, SIGNAL( triggered() ), this, SLOT( close() ) );
    connect(actionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );

    but still no success. Funnyly the first connect works as expected. When I click the close button in the menu, the app closes...

  • Moderators

    Ah wait, you didn't declare about() as a member of your class!

    Change it into:

    void qimageview::about()

    Then rerun MOC, and recompile.

  • Damned. Thanks for lighting my mind. What a stupid mistake...

    But I still get the error message.

Log in to reply