Important: Please read the Qt Code of Conduct -

[solved]Cannot call slot=*(

  • LogWindow.h
    class LogWindow : public QMainWindow
    .... //another code
    public slots:
    void replyClicked();
    void msgSent();

    class LogBrain : public LogWindow
    public slots:
    void textProcessing();

    void LogWindow::replyClicked()
    emit msgSent();

    void LogBrain::textProcessing()

    int main(int argc, char *argv[])
    QApplication logApp(argc, argv);
    LogWindow *mainWnd = new LogWindow;
    LogBrain *logMind = new LogBrain;

    QObject::connect(mainWnd->ui.pushButton, SIGNAL(clicked()), mainWnd, SLOT(replyClicked()));
    QObject::connect(mainWnd, SIGNAL(msgSent()), logMind, SLOT(textProcessing()));
    return logApp.exec();


    Can't call textProcessing() slot.
    I put a breakpoint where signal msgSent() must be emitted and until this moment everything works fine. But then this signal doesn't call slot textProcessing(). I cannot understand what's the problem. I created new project and wrote similar code and there everything is ok and textProcessing() calls without any problems.

  • Lifetime Qt Champion

    @AntonZelenin said:
    I am wondering if LogBrian also need a Q_OBJECT in top of class def?

  • @mrjj

    It works!) It seemed to me, that I tried to add Q_OBJECT but there was an error, something with moc file, but now everything is good, strange. Thanks

  • Lifetime Qt Champion

    Well, when I add Q_OBJECT to a class. I often go an delete whole build folder as its sometimes a bit
    hard to make it run moc fully or something like that. Sometimes a "Clean" also works.

  • Lifetime Qt Champion


    The thing to do when you add/remove the Q_OBJECT macro is to re-run qmake (in the Build menu of Qt Creator). That will it turn trigger moc to run again and see that your class needs to be mocked

  • @SGaist
    Yeah, I have already realized that, but thanks)

Log in to reply