Author Topic: The Link's error for Qt Application  (Read 3512 times)

Offline xinlnix

  • Single posting newcomer
  • *
  • Posts: 9
The Link's error for Qt Application
« on: November 09, 2005, 11:13:51 pm »
I copy Qt example:C:\Qt\4.0.1\examples\widgets\calculator to myself path;I create Qt Application project by Code::Blocks,Add all .cpp and .h to the project,then I compile the project. It shows that #include <QtGui>  QtGui no such file or directory. I modify the code as : #include <QtGui/QtGui>, the compiler is pass ,but at the build time,it shows the message below:

Project   : qtApp
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\Administrator\My Documents\calculator\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: button.cpp
Linking executable: C:\Documents and Settings\Administrator\My Documents\calculator\calculator.exe
.objs\calculator.o:calculator.cpp:(.text+0x181): undefined reference to `vtable for Calculator'
.objs\calculator.o:calculator.cpp:(.text+0x18d): undefined reference to `vtable for Calculator'
.objs\calculator.o:calculator.cpp:(.text+0x1c2d): undefined reference to `vtable for Calculator'
.objs\calculator.o:calculator.cpp:(.text+0x1c39): undefined reference to `vtable for Calculator'
.objs\calculator.o:calculator.cpp:(.text$_ZN10Calculator2trEPKcS1_[Calculator::tr(char const*, char const*)]+0x1c): undefined reference to `Calculator::staticMetaObject'
.objs\calculator.o:calculator.cpp:(.text$_Z12qobject_castIP6ButtonET_P7QObject[Button* qobject_cast<Button*>(QObject*)]+0x10): undefined reference to `Button::staticMetaObject'
.objs\main.o:main.cpp:(.text$_ZN10CalculatorD1Ev[Calculator::~Calculator()]+0x3a): undefined reference to `vtable for Calculator'
.objs\main.o:main.cpp:(.text$_ZN10CalculatorD1Ev[Calculator::~Calculator()]+0x46): undefined reference to `vtable for Calculator'
.objs\button.o:button.cpp:(.text+0x155): undefined reference to `vtable for Button'
.objs\button.o:button.cpp:(.text+0x161): undefined reference to `vtable for Button'
.objs\button.o:button.cpp:(.text+0x2d3): undefined reference to `vtable for Button'
.objs\button.o:button.cpp:(.text+0x2df): undefined reference to `vtable for Button'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings
 
I can't build the application,and I don't know why? Can anyone help me, Thanks a lots!

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: The Link's error for Qt Application
« Reply #1 on: November 10, 2005, 08:45:12 am »
The undefined reference to vtable messages mean that you have the Q_OBJECT specifier in the declararion of your class and you have not passed it through the meta object compiler (moc) to build some intermediate source that your app needs or that you're using a qt gui class as a member without Q_OBJECT in your declaration. One easy way to get around is to pass your header files through moc (see qt docs) and then include the moc output cpp files to your project. You'll probably (uhmmm certainly) have problems if you use resource files or ui files. If you search the forum you'll find many suggestions on how to get around most of the problems. I am a qt freak myself (though wxWidgets are starting to grow on me ;)) and I've patched cb to work with qt tools and I've built all the qt examples with it. When I find the time I'll wrap it up in a plugin and submit it.
Life would be so much easier if we could just look at the source code.

Offline xinlnix

  • Single posting newcomer
  • *
  • Posts: 9
Re: The Link's error for Qt Application
« Reply #2 on: November 12, 2005, 09:54:58 am »
thank you yop,  I will wait you code.