[solved]Cannot call slot=*(



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

    LogBrain.h
    class LogBrain : public LogWindow
    {
    ....
    public slots:
    void textProcessing();
    };

    LogWindow.cpp
    void LogWindow::replyClicked()
    {
    ...
    emit msgSent();
    }

    LogBrain.cpp
    void LogBrain::textProcessing()
    {
    ....
    }

    main.cpp
    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()));
    
    mainWnd->show();
    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.


  • Qt Champions 2016

    @AntonZelenin said:
    Hi
    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


  • Qt Champions 2016

    @AntonZelenin
    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

    Hi,

    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
 

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