qt-interest@trolltech.com
[Top] [All Lists]

Re: udefined reference to vtable, how get rid of?

Subject: Re: udefined reference to vtable, how get rid of?
From: Tom Bradley
Date: Wed, 10 Nov 2004 16:14:17 -0700
tj wrote:

Creating the .h and putting the class declaration

class myTextEdit : public QTextEdit
{
  Q_OBJECT
public:
myTextEdit(QWidget *parent=0, const char *name=0);
int count;

public slots:
void append(QString line);
void putLine(void);

};

caused syntax errors when making, but adding
#include <qtextedit.h>
at the beginning of the .h file stopped that and lo and behold my app ran like I expected.

I don't understand the need for including the qtextedit.h file. In main.cpp it is included AHEAD of the main.h include. Shouldn't that have satisfied main.h's need for qtextedit.h? Or is it needed that specific way for the moc generation?

Anyway, I got it to build and run and learned how.

Thanks to ALL who responded to this newbie.

tj

Paul Ruetz wrote:

I assume you have only one source file, say 'main.cpp'.

When you define signals or slots without having a header file, AFAIK you have to do two steps manually, as they are:

1. Call the 'moc' manually:
    moc main.cpp > moc_main.cpp

2. Include the 'moc_main.cpp' at the end of your 'main.cpp':
    #include "moc_main.cpp"

To avoid these steps, always use header files when using signals/slots.

Hope this helps,

Paul


tj wrote:


--
List archive and information: http://lists.trolltech.com/qt-interest/


the #include is scoped to main.cpp so the moc file that is created from the .h file doesn't know about the textedit.h file which is why you needed it in the main.h file. You should always put the #include (if instantiating) or a forward reference(if only declaring a pointer) in each file, you shouldn't make any assumtions about the order in which files are processed.



--
Tom Bradley
Titan Security Systems
Software Engineer
505.344.7455 x156

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>