Qt World Summit: Register Today!

"unused parameter 'parent'" and undefined symbols

  • Hey, I've been trying to write my own Qt program from scratch, and but I've been getting this error:

    bq. usr/bin/clang++ -c -pipe -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.8 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/local/share/qt4/mkspecs/macx-g++ -I. -I. -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I. -I/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/opt/local/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/opt/local/include -F/opt/local/Library/Frameworks -F/opt/local/lib -o gui.o gui.cpp
    /usr/bin/clang++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.8 -o secretproject.app/Contents/MacOS/secretproject gui.o -F/opt/local/Library/Frameworks -F/opt/local/lib -F/opt/local/Library/Frameworks -F/opt/local/lib -L/opt/local/lib -framework QtGui -framework QtCore
    Undefined symbols for architecture x86_64:
    "vtable for TopSecret", referenced from:
    TopSecret::TopSecret(QWidget*) in gui.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [secretproject.app/Contents/MacOS/secretproject] Error 1

    So apparently this error is caused by me not defining all functions. But I swear I defined all the functions in my QWidget subclass:
    @#include <iostream>
    #include <QApplication>
    #include <QWidget>
    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QPushButton>
    #include <QCheckBox>
    #include <QTextBrowser>
    class TopSecret: public QWidget
    TopSecret(QWidget *parent=0);
    private slots:
    void setverbose();
    //void openfilepls();
    bool verbose;
    QVBoxLayout *inputvsoutput;
    QHBoxLayout *inputoptions;
    QPushButton *openbutton;
    QCheckBox *verbosecheckbox;
    QTextBrowser *dcmdumpoutput;

    TopSecret::TopSecret(QWidget *parent):QWidget(parent)
    verbose = FALSE;
    inputvsoutput = new QVBoxLayout();
    inputoptions = new QHBoxLayout();
    openbutton = new QPushButton("Open");
    verbosecheckbox = new QCheckBox("Verbose");
    dcmdumpoutput = new QTextBrowser();


    void TopSecret::setverbose(){
    std::cout << "verbose checkbox state: " << verbosecheckbox->checkState() << std::endl;

  • Re-run qmake and rebuild project.

  • I ran a make clean, qmake -project, qmake, make and it still fails with the same error.

  • Moderators

    You don't by any chance have all this code in a .cpp? QObject based class declaration should be in a header.

  • Well, yes, I do have all this in a cpp. What's the difference, it gets included anyway.

    EDIT: What the... I put it in a separate .h file, and included it, and now it compiles without problems! What the hell is going on?

  • Moderators

    You mean you have #include "gui.cpp" somewhere??? That is bad on its own.

    But here the problem is something else. You inherit from QObject, which has quite a few virtual methods that you don't implement (and shouldn't!).

    Each time you run qmake a tool called moc (meta object compiler) runs on all headers and generates a file moc_YOURCLASS.cpp which contains implementation of those virtual methods.
    Because you placed your class declaration in a .cpp moc can't see it and doesn't generate it so you get this linker error of missing implementation.

    Aside from this Qt specific topic it's a good style to place class declarations in headers. There are lots of reasons for it (use your favorite search engine) and it's the C++ way, so do that and you'll avoid lots of problems in the future.

  • No, it's all just in one big gui.cpp Nevertheless, point taken. Thanks for your help!

Log in to reply