Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Object::connect: No such slot [SOLVED]



  • whe I start program this shows in console "Object::connect: No such slot QMainWindow::Refresh() in /home/default/projects/MainProject/WindowDiscoverServer.cpp:10
    Object::connect: (sender name: 'ButtonRefresh')
    Object::connect: (receiver name: 'MainWindow') "

    WindowDiscoverServer.h
    [code]
    class WindowDiscoverServer : public QMainWindow
    {

    //Q_OBJECT

    public:
    WindowDiscoverServer(QWidget* parent = 0);
    virtual ~WindowDiscoverServer();

    public slots:
    void Refresh();

    private:

    Ui_MainWindow *ui;

    };
    [/code]

    WindowDiscoverServer.cpp
    [code]
    WindowDiscoverServer::WindowDiscoverServer(QWidget* parent): QMainWindow(parent), ui(new Ui_MainWindow)
    {
    ui->setupUi(this);

    QObject::connect(ui->ButtonQuit, SIGNAL(clicked()), this, SLOT(close()));
    QObject::connect(ui->ButtonRefresh, SIGNAL(clicked()), this, SLOT(Refresh()));
    }
    WindowDiscoverServer::~WindowDiscoverServer()
    {
    delete ui;
    }

    void WindowDiscoverServer::Refresh()
    {
    std::cout << "Refresh " << std::endl;
    }
    [/code]



  • Hi,

    to use signals/slots you have to uncomment Q_OBJECT inside your class definition


  • Moderators

    Hi, and welcome to the Qt Dev Net!

    @Stanislav said:

    WindowDiscoverServer.h

    class WindowDiscoverServer : public QMainWindow 
    {
    
      //Q_OBJECT
    

    Why did you comment out the Q_OBJECT macro? Your class needs it to implement new slots.

    Un-comment the macro and run qmake.



  • when i uncomment my compilator (Kdevelop) return this error "/home/default/projects/MainProject/WindowDiscoverServer.cpp:5: undefined reference to `vtable for WindowDiscoverServer'

    p.s. I use cmake not qmake


  • Moderators

    @Stanislav said:

    when i uncomment my compilator (Kdevelop) return this error "/home/default/projects/MainProject/WindowDiscoverServer.cpp:5: undefined reference to `vtable for WindowDiscoverServer'

    Yes, that's why I said you need to run qmake after you uncomment it.

    p.s. I use cmake not qmake

    I don't know how to do it in cmake, but you can (i) uncomment Q_OBJECT, (ii) delete your build tree, and then then (iii) rebuild everything from the beginning.


Log in to reply