Congratulations to our 2022 Qt Champions!

Build error when subclassing of subclassing from QObject

  • build error is happen when subclassing of subclassing from QObject.

    is there any solution to avoid this problem?

    this is source code & error

    ! code & error)!

  • this is my qt version

    Qt Creator 3.3.0 (opensource)
    Based on Qt 5.4.0 (MSVC 2010, 32 bit)

    Built on Dec 8 2014 at 15:24:21

  • Qt Champions 2017

    Do you need Q_OBJECT in 'sub' class ? This is the source of your error.

  • i need to send signal in both base and sub classes,
    so i wrote the Q_OBJECT in both class.

    if writing Q_OBJECT in both class is impossible, how can i send signal in both classes?

    build error is also happen when writing emit function to send signal without Q_OBJECT in Sub class

    class Sub : public Base
    void sendSigKey(const QString &key) const;

    void Sub::send()
    emit sendSigKey("asdf");
    error: undefined reference to `Sub::sendSigKey(QString const&) const'

  • Did you do a clean qmake ?

    Delete your build folder
    Run qmake
    Build your project.

    After that i think you have to remove the const qualifier in your constructor !

  • Lifetime Qt Champion


    To add to my fellow, when adding/removing the Q_OBJECT macro you need to run qmake once to update the build part. Then it should build cleanly

  • thank you, SGaist

    your reply sloved my problem.

Log in to reply