Qt undefined reference to vtable

I'm writing a simple, simple Qt app, and I'm getting the useless "undefined reference to vtable" message from g++, and I have no idea why. I have one class which inherits from qwidget, defined like this:
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef FCRYPT
#define FCRYPT

#include "ui_fcrypt.h"

class FCrypt : public QWidget, private Ui::FCrypt_window {
	Q_OBJECT
	public:
		FCrypt(QWidget *parent = 0);
};

#endif 


and implemented like this (for the time being):
1
2
3
4
5
#include "fcrypt.h"

FCrypt::FCrypt(QWidget *parent) {
	setupUi(this);
}


This is the output from make:

release/fcrypt.o:fcrypt.cpp:(.text+0x2b): undefined reference to `vtable for FCr
ypt'
release/fcrypt.o:fcrypt.cpp:(.text+0x32): undefined reference to `vtable for FCr
ypt'
release/fcrypt.o:fcrypt.cpp:(.text+0x8f): undefined reference to `vtable for FCr
ypt'
release/fcrypt.o:fcrypt.cpp:(.text+0x96): undefined reference to `vtable for FCr
ypt'
collect2: ld returned 1 exit status
make[1]: *** [release\FCrypt.exe] Error 1
make[1]: Leaving directory `C:/Users/terry/Desktop/FCrypt'
make: *** [release] Error 2


I've done this a dozen times before, but this is the first time I'm having this problem. Any ideas?
http://bytes.com/topic/c/answers/161894-undefined-reference-vtable#post623578

(When I get errors that I don't understand, I google them and in 99% of the cases something useful shows up in the first few hits. Just for future reference ;)

Regards
Thanks, but that doesn't really answer the problem. The cause for the error in the question in your link was a missing implementation of a declared virtual method, but none of this is the case for me.
No, that was not the idea. The cause is not missing implementation of a declared virtual method as you say, but the lack of translation unit (.cpp file) that implements at least one non-inline member function specifically for this class. If you think carefully, you will see that those are different things. The compiler needs this so that it can determine in which object file it has to dump the vtable and other service information pertaining to the class.

I had the same problem some while ago and although I have forgotten the exact details, this turned out to be the explanation. May be the constructor doesn't count as member function. My advice is that you should experiment with implementing some method for this class.

Regards
Ah, ok, I didn't look closely enough at it. Thanks;) I'll experiment a bit more with it.
Try a virtual destructor virtual ~FCrypt();
@fafner: You're using the Q_OBJECT macro. This macro is define in qobjectdefs.h in the QtCore module and simply adds virtual function declarations to your class declaration. Since there is no definition done anywhere, you're code has some undefined references in the executables text segment which then results in linker errors.

The simple solution is to run the meta object compiler(moc) provided by Qt. The moc creates the code for the functions defined by Q_OBJECT and everything works fine.
Refer to http://doc.qt.nokia.com/latest/moc.html for instructions.

Note: If you want to use signals and slots, which you most certainly will want to do if you're planning on using buttons and so on, you'll have to use Q_OBJECT in your class declaration anyway. It's well worth your time reading up signals and slots as well. See http://doc.trolltech.com/4.7/signalsandslots.html for further information.

Thomas
Topic archived. No new replies allowed.