Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "unused parameter 'parent'" and undefined symbols
Forum Updated to NodeBB v4.3 + New Features

"unused parameter 'parent'" and undefined symbols

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ritchan
    wrote on last edited by
    #1

    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
    {
    Q_OBJECT
    public:
    TopSecret(QWidget *parent=0);
    ~TopSecret();
    private slots:
    void setverbose();
    //void openfilepls();
    private:
    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();

    inputoptions->addWidget(openbutton);
    inputoptions->addWidget(verbosecheckbox);
    inputvsoutput->addLayout(inputoptions);
    inputvsoutput->addWidget(dcmdumpoutput);
    setLayout(inputvsoutput);
    };
    TopSecret::~TopSecret()
    {};

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

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      Re-run qmake and rebuild project.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ritchan
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ritchan
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                ritchan
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved