Results 1 to 5 of 5

Thread: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec edition)

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec edition)

    I have searched for another similar threads about "undefined Reference: vtable" but still can't figured out how to solve this

    my OS is windows xp sp3
    my compiler is gcc4.5 mingw
    my IDE is code::blokcs 10.05
    my Qt version is 4.7.1

    below is the code come from the book--C++ GUI Programming with Qt4, sec edition
    Qt Code:
    1. #ifndef FINDDIALOG_H
    2. #define FINDDIALOG_H
    3.  
    4. #include <QDialog>
    5.  
    6. class QCheckBox;
    7. class QLabel;
    8. class QLineEdit;
    9.  
    10. class FindDialog : public QDialog
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. FindDialog(QWidget *parent = 0);
    16.  
    17. signals:
    18. void findNext(const QString &str, Qt::CaseSensitivity cs);
    19. void findPrevious(const QString &str, Qt::CaseSensitivity cs);
    20.  
    21. private slots:
    22. void findClicked();
    23. void enableFindButton(const QString &text);
    24.  
    25. private:
    26. QLabel *label;
    27. QLineEdit *lineEdit;
    28. QCheckBox *caseCheckBox;
    29. QCheckBox *backwardCheckBox;
    30. QPushButton *findButton;
    31. QPushButton *closeButton;
    32. };
    33.  
    34. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "finddialog.h"
    4.  
    5. FindDialog::FindDialog(QWidget *parent)
    6. : QDialog(parent)
    7. {
    8. label = new QLabel(tr("Find &what:"));
    9. lineEdit = new QLineEdit;
    10. label->setBuddy(lineEdit);
    11.  
    12. caseCheckBox = new QCheckBox(tr("Match &case"));
    13. backwardCheckBox = new QCheckBox(tr("Search &backward"));
    14.  
    15. findButton = new QPushButton(tr("&Find"));
    16. findButton->setDefault(true);
    17. findButton->setEnabled(false);
    18.  
    19. closeButton = new QPushButton(tr("Close"));
    20.  
    21. connect(lineEdit, SIGNAL(textChanged(const QString &)),
    22. this, SLOT(enableFindButton(const QString &)));
    23. connect(findButton, SIGNAL(clicked()),
    24. this, SLOT(findClicked()));
    25. connect(closeButton, SIGNAL(clicked()),
    26. this, SLOT(close()));
    27.  
    28. QHBoxLayout *topLeftLayout = new QHBoxLayout;
    29. topLeftLayout->addWidget(label);
    30. topLeftLayout->addWidget(lineEdit);
    31.  
    32. QVBoxLayout *leftLayout = new QVBoxLayout;
    33. leftLayout->addLayout(topLeftLayout);
    34. leftLayout->addWidget(caseCheckBox);
    35. leftLayout->addWidget(backwardCheckBox);
    36.  
    37. QVBoxLayout *rightLayout = new QVBoxLayout;
    38. rightLayout->addWidget(findButton);
    39. rightLayout->addWidget(closeButton);
    40. rightLayout->addStretch();
    41.  
    42. QHBoxLayout *mainLayout = new QHBoxLayout;
    43. mainLayout->addLayout(leftLayout);
    44. mainLayout->addLayout(rightLayout);
    45. setLayout(mainLayout);
    46.  
    47. setWindowTitle(tr("Find"));
    48. setFixedHeight(sizeHint().height());
    49. }
    50.  
    51. void FindDialog::findClicked()
    52. {
    53. QString text = lineEdit->text();
    54. Qt::CaseSensitivity cs =
    55. caseCheckBox->isChecked() ? Qt::CaseSensitive
    56. : Qt::CaseInsensitive;
    57. if (backwardCheckBox->isChecked()) {
    58. emit findPrevious(text, cs);
    59. } else {
    60. emit findNext(text, cs);
    61. }
    62. }
    63.  
    64. void FindDialog::enableFindButton(const QString &text)
    65. {
    66. findButton->setEnabled(!text.isEmpty());
    67. }
    To copy to clipboard, switch view to plain text mode 

    when I press the F9 button, the compiler always give me error message like
    undefined reference to 'vtable for findDialog'
    undefined reference to `FindDialog::staticMetaObject'
    The example of chapter1 of this book could be compiled perfectly, but the example of
    the chapter2 can't work at all.
    Thanks a lot

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi

    your IDE is not running qmake and/or not linking to the files generated by moc.

    try to compile the example on command line via
    qmake
    make (or mingw-make )

  3. The following user says thank you to nish for this useful post:

    stereoMatching (19th January 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi

    Thanks for your reply
    I open the MinGW Command Prompt, and type the command
    qmake -project
    qmake
    make
    below is the error messages
    mingw32-make[1]:***[debug\find.exe] Error 1
    mingw32-make : *** [debug] Error 2
    what mistakes do I make?Thanks

    ps : I download my gcc from this site
    htp://tdm-gcc.tdragon.net/


    Added after 24 minutes:


    I solved the probelm
    <QT4 directory>\bin\moc.exe myfile.h -o moc_myfile.cpp
    Then include the file moc_myfile.cpp in the project as well.
    How could I make the IDE do this automatically for me?
    Thanks
    Last edited by stereoMatching; 19th January 2011 at 13:16.

  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi

    Maybe you should use Qt Creator (is an very good IDE, and it "looks" exactly the same on all platforms)
    It comes together with Qt SDK for Windows.

    Or use Visual Studio or Eclipse, Qt framework has add-ins that integrate the Qt tools into those.

  6. The following user says thank you to Zlatomir for this useful post:

    stereoMatching (19th January 2011)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi

    The header file containing Q_OBJECT macro has to be present in the HEADERS variable of a qmake project and qmake needs to be ran after adding the macro to the file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    stereoMatching (20th January 2011)

Similar Threads

  1. Undifined Refrence: vtable
    By mweber1488 in forum Newbie
    Replies: 10
    Last Post: 5th January 2011, 17:28
  2. error: undefined refrence
    By motsh in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 3rd May 2009, 15:22
  3. vtable problems
    By high_flyer in forum Qt Programming
    Replies: 6
    Last Post: 3rd September 2007, 13:52
  4. silly undefined refrence to main
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 16th November 2006, 09:41
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.