Results 1 to 3 of 3

Thread: Strange linker error - can anyone help? (Qt 4.1.2)

  1. #1
    Join Date
    May 2006
    Location
    Gera, Thuringia, Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Thumbs down Strange linker error - can anyone help? (Qt 4.1.2)

    Hello,

    is there anybody, who can explain to me the cause for the following strange linker error in my Xcode based Qt project?

    /usr/bin/ld: Undefined symbols:
    vtable for GoButton
    /Users/Norbert/MyCode/SlotTest01/build/SlotTest01.build/Debug/SlotTest01.build/Objects-normal/ppc/main.o reference to undefined vtable for GoButton
    collect2: ld returned 1 exit status
    /usr/bin/ld: Undefined symbols:
    vtable for GoButton
    /Users/Norbert/MyCode/SlotTest01/build/SlotTest01.build/Debug/SlotTest01.build/Objects-normal/ppc/main.o reference to undefined vtable for GoButton
    collect2: ld returned 1 exit status


    For better understanding:

    I intended to make just a simple program for testing selfmade slots. The code of the main.cpp ist the following:

    #include <qapplication.h>
    #include <qpushbutton.h>
    #include <qobject.h>
    #include <qstring.h>
    #include <qwidget.h>

    #include <unistd.h>

    class GoButton : public QPushButton
    {
    Q_OBJECT
    public:
    GoButton(const QString& text, QWidget* parent)
    : QPushButton(text, parent)
    {
    connect(this, SIGNAL(clicked()), this, SLOT(go()));
    }
    public slots:
    void go()
    {
    static int count = 0;
    count++;

    if(count > 5)
    {
    qApp->quit(); //Finish after 5th click
    }

    }

    };

    int main(int argc, char** argv)
    {
    QApplication a(argc, argv);

    GoButton* b = new GoButton("Press Me, Please!", 0);

    b->show();

    QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));

    return a.exec();
    }



    I made a Xcode project by processing the main.cpp as the only file in my project directory as follows:

    I typed: qmake –project

    The resulting Qt .pro file looks as follows:

    ################################################## ####################
    # Automatically generated by qmake (2.00a) Fri Jun 16 13:07:34 2006
    ################################################## ####################

    TEMPLATE = app
    TARGET +=
    DEPENDPATH += .
    INCLUDEPATH += .

    # Input
    SOURCES += main.cpp

    Then I typed: qmake

    Then I opened the Xcode project and started a build process. All compiler action seemed to be o. k..The linker error above occured.


    I cannot explain to me, what could be wrong here.

    Can anyone? I hope ...

    Have a nice weekend, you all!

    Norbert

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange linker error - can anyone help? (Qt 4.1.2)

    You must run moc utility on every class that contains Q_OBJECT macro to generate missing code. Usually qmake does this for you, but unfortunately it only checks header files for Q_OBJECT, so moc won't be run if you have a class definition inside a .cpp file.

    The easiest solution is to add #include "main.moc" at the end of main.cpp file (don't forget to rerun qmake). This tells qmake that it has to run moc on given file.

  3. The following 3 users say thank you to jacek for this useful post:

    aamer4yu (4th October 2006), Dr. Norbert Prang (16th June 2006), Intangir (16th June 2006)

  4. #3
    Join Date
    May 2006
    Location
    Gera, Thuringia, Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Strange linker error - can anyone help? (Qt 4.1.2)

    Hi,

    thanks for quick and useful reply! That works really phantastic. Thanks again.

    Have a nice weekend.
    Norbert

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.