Important: Please read the Qt Code of Conduct -

Unresolved external symbol signal

  • I created an instance of QGuiApplication and a signal in order test if it works and I always get that the compiler could not resolve external symbols:


    #ifndef TEST_HPP
    #define TEST_HPP
    #include <QGuiApplication>
    class test : public QGuiApplication
      explicit test(int &argc, char **argv);
      void signalTest();
    #endif // TEST_HPP


    #include "test.hpp"
    test::test(int &argc, char **argv) : QGuiApplication(argc, argv)
      emit signalTest();

    I tried to clean the build, remove the built files and build again, and nothing.

  • Lifetime Qt Champion

    add Q_OBJECT to your class
    class test : public QGuiApplication

    and clean, and rebuild all

    All classes that uses signals&slots must have this

  • @mrjj That is weird, I tried and I got a lot of errors before, maybe because I needed to delete/clean first.
    I thought that Q_OBJECT was only supposed to be used with QObject classes.

    Thank you, it is solved.

  • Lifetime Qt Champion

    well the Q_OBJECT is used by the moc.exe compiler and sometimes its
    a bit lazy it seems. so when anything else fails, i delete the build folder :)
    Well, its need for the meta system used for signals.
    But frankly I never tried to make a QApplication subclass but normally that the
    case with all other subclassing.
    Update: QApplication is a QCoreApplication which inherits from QObject

  • @mrjj You are right about being a bit lazy. I need to delete the build folder as well sometimes, specially when creating a new class, for sure I will get errors and I need to delete the folder and build again.

  • Lifetime Qt Champion

    note. sometimes running qmake will also work.
    It my understanding that "make file" calls moc.exe
    But i have had cases where it would first like after I deleted build folder.
    (regardless of clean/qmake/rebuild all)

Log in to reply