Can't compile Qt code (again)

I'm up to this chapter of the official Qt tutorial. I've copied and pasted the three source files and I'm trying to compile them but I get these messages:

Code:
> g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -I/usr/local/include -L/usr/local/lib/qt4 -lQtGui -lQtCore main.cpp lcdrange.cpp
/var/tmp//ccP3Tdr9.o(.text+0x194): In function `LCDRange::LCDRange(QWidget*)':
: undefined reference to `vtable for LCDRange'
/var/tmp//ccP3Tdr9.o(.text+0x19e): In function `LCDRange::LCDRange(QWidget*)':
: undefined reference to `vtable for LCDRange'
/var/tmp//ccP3Tdr9.o(.text+0x434): In function `LCDRange::LCDRange(QWidget*)':
: undefined reference to `vtable for LCDRange'
/var/tmp//ccP3Tdr9.o(.text+0x43e): In function `LCDRange::LCDRange(QWidget*)':
: undefined reference to `vtable for LCDRange'
>

Can anyone who knows about Qt shed some light on what's happening?

Thanks.
 
Thanks expl, but I don't think that's the problem because I get the same error when using qmake.

I see now that the code *compiles* fine, it's the linking that is throwing the errors. I've googled undefined reference to vtable and it seems this is a common error (see here, here, here and here), but I don't know enough C++ to understand the explanations.

All of the threads on other forums seem to point to the same FAQ page, http://gcc.gnu.org/faq.html#vtables, but again, I don't understand it.

I gathered it's something about class definitions not being in header files. Any C++ experts care to voice their opinions?

Thanks
 
There is nothing complicated like I said you need to use Qt4 moc, it will generate the needed stuff then you just compile it and link it with rest of your project. Like this:

Code:
moc-qt4 -o lcdrange-moc.cpp lcdrange.h
g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -I/usr/local/include -L/usr/local/lib/qt4 -lQtGui -lQtCore main.cpp lcdrange.cpp lcdrange-moc.cpp
 
Back
Top