Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, June 2007
'Undefined reference to vtable' when inheriting from QObject


Message 1 in thread

Hi folks,

Just trying to create a simple class called Browser composed of a QTextBrowser 
and a JsDomDocument (JsDomDocument inherits from QDomDocument).

Why would I be getting the following "undefined reference to vtable for 
Browser" error? I have the constructor in the .cpp file correctly declared in 
hte .h file - I think???

Thanks for any help,
Dec



/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
undefined reference to `vtable for Browser'
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
undefined reference to `vtable for Browser'
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
undefined reference to `vtable for Browser'
browser.o: In function `Browser':
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34: 
undefined reference to `vtable for Browser'
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34: 
undefined reference to `vtable for Browser'
collect2: ld returned 1 exit status
gmake[1]: *** [../bin/frogface] Error 1
gmake: *** [sub-src-make_default] Error 2
*** Exited with status: 2 ***


*******************************************************************
browser.h
*******************************************************************
#ifndef BROWSER_H
#define BROWSER_H

#include <QTextBrowser>;
#include "jsdomdocument.h";
#include <QObject>
/**
	@author Declan McGrath <declanmcgrath@xxxxxxxxxxxx>
*/
class Browser : public QObject
{
Q_OBJECT

private:
    QTextBrowser& m_textBrowser;
    JsDomDocument m_domDoc;

public:
    Browser(QTextBrowser& textBrowser, QObject* parent = 0);
    ~Browser();

public slots:
    JsDomDocument document()
    { return m_domDoc; };

    void setXHtml(const QString& xhtml);
    QString toXHtml() const;
};

#endif

*******************************************************************
browser.cpp
*******************************************************************
#include "browser.h"

Browser::Browser(QTextBrowser& textBrowser, QObject* parent /*= 0*/)
:
m_textBrowser(textBrowser),
QObject(parent)
{
}

Browser::~Browser()
{
}

void Browser::setXHtml(const QString& xhtml)
{
    m_domDoc.setContent(xhtml);
    m_textBrowser.setHtml(this->toXHtml());
}

QString Browser::toXHtml() const
{
    return m_domDoc.toString(2);
}

--
 [ signature omitted ] 

Message 2 in thread

Are you sure, you are moc'ing your header files?
Are you using qmake to build your Makefiles?

Usually this linker message happens whenever you forget to include the 
Q_OBJECT-Macro or you forget to moc your header files.

Regards,
Malte



Declan McGrath <declanmcgrath@xxxxxxxxxxxx> schrieb am 29.06.2007 
13:08:18:

> Hi folks,
> 
> Just trying to create a simple class called Browser composed of a 
> QTextBrowser 
> and a JsDomDocument (JsDomDocument inherits from QDomDocument).
> 
> Why would I be getting the following "undefined reference to vtable for 
> Browser" error? I have the constructor in the .cpp file correctly 
declared in 
> hte .h file - I think???
> 
> Thanks for any help,
> Dec
> 
> 
> 
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38: 
> undefined reference to `vtable for Browser'
> browser.o: In function `Browser':
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34: 
> undefined reference to `vtable for Browser'
> collect2: ld returned 1 exit status
> gmake[1]: *** [../bin/frogface] Error 1
> gmake: *** [sub-src-make_default] Error 2
> *** Exited with status: 2 ***
> 
> 
> *******************************************************************
> browser.h
> *******************************************************************
> #ifndef BROWSER_H
> #define BROWSER_H
> 
> #include <QTextBrowser>;
> #include "jsdomdocument.h";
> #include <QObject>
> /**
>    @author Declan McGrath <declanmcgrath@xxxxxxxxxxxx>
> */
> class Browser : public QObject
> {
> Q_OBJECT
> 
> private:
>     QTextBrowser& m_textBrowser;
>     JsDomDocument m_domDoc;
> 
> public:
>     Browser(QTextBrowser& textBrowser, QObject* parent = 0);
>     ~Browser();
> 
> public slots:
>     JsDomDocument document()
>     { return m_domDoc; };
> 
>     void setXHtml(const QString& xhtml);
>     QString toXHtml() const;
> };
> 
> #endif
> 
> *******************************************************************
> browser.cpp
> *******************************************************************
> #include "browser.h"
> 
> Browser::Browser(QTextBrowser& textBrowser, QObject* parent /*= 0*/)
> :
> m_textBrowser(textBrowser),
> QObject(parent)
> {
> }
> 
> Browser::~Browser()
> {
> }
> 
> void Browser::setXHtml(const QString& xhtml)
> {
>     m_domDoc.setContent(xhtml);
>     m_textBrowser.setHtml(this->toXHtml());
> }
> 
> QString Browser::toXHtml() const
> {
>     return m_domDoc.toString(2);
> }
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 3 in thread

Have you declared the destructor and defined it even though it is empty
? Some times the vtable corruption happens if the destructor is declared
and not defined.

Regards
Vidya. 

-----Original Message-----
From: Malte Witt [mailto:malte.witt@xxxxxxxxxxxxx] 
Sent: Friday, June 29, 2007 4:42 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: 'Undefined reference to vtable' when inheriting from
QObject

Are you sure, you are moc'ing your header files?
Are you using qmake to build your Makefiles?

Usually this linker message happens whenever you forget to include the
Q_OBJECT-Macro or you forget to moc your header files.

Regards,
Malte



Declan McGrath <declanmcgrath@xxxxxxxxxxxx> schrieb am 29.06.2007
13:08:18:

> Hi folks,
> 
> Just trying to create a simple class called Browser composed of a 
> QTextBrowser and a JsDomDocument (JsDomDocument inherits from 
> QDomDocument).
> 
> Why would I be getting the following "undefined reference to vtable 
> for Browser" error? I have the constructor in the .cpp file correctly
declared in 
> hte .h file - I think???
> 
> Thanks for any help,
> Dec
> 
> 
> 
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
: 
> undefined reference to `vtable for Browser'
> browser.o: In function `Browser':
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34
: 
> undefined reference to `vtable for Browser'
> 
/mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34
: 
> undefined reference to `vtable for Browser'
> collect2: ld returned 1 exit status
> gmake[1]: *** [../bin/frogface] Error 1
> gmake: *** [sub-src-make_default] Error 2
> *** Exited with status: 2 ***
> 
> 
> *******************************************************************
> browser.h
> *******************************************************************
> #ifndef BROWSER_H
> #define BROWSER_H
> 
> #include <QTextBrowser>;
> #include "jsdomdocument.h";
> #include <QObject>
> /**
>    @author Declan McGrath <declanmcgrath@xxxxxxxxxxxx> */ class 
> Browser : public QObject { Q_OBJECT
> 
> private:
>     QTextBrowser& m_textBrowser;
>     JsDomDocument m_domDoc;
> 
> public:
>     Browser(QTextBrowser& textBrowser, QObject* parent = 0);
>     ~Browser();
> 
> public slots:
>     JsDomDocument document()
>     { return m_domDoc; };
> 
>     void setXHtml(const QString& xhtml);
>     QString toXHtml() const;
> };
> 
> #endif
> 
> *******************************************************************
> browser.cpp
> *******************************************************************
> #include "browser.h"
> 
> Browser::Browser(QTextBrowser& textBrowser, QObject* parent /*= 0*/)
> :
> m_textBrowser(textBrowser),
> QObject(parent)
> {
> }
> 
> Browser::~Browser()
> {
> }
> 
> void Browser::setXHtml(const QString& xhtml) {
>     m_domDoc.setContent(xhtml);
>     m_textBrowser.setHtml(this->toXHtml());
> }
> 
> QString Browser::toXHtml() const
> {
>     return m_domDoc.toString(2);
> }
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with

> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 4 in thread

If you are using qmake sometimes you have to delete all your Makefiles
and regenerate them to get your new header file moc'ed


On Fri, 2007-06-29 at 17:22 +0530, vidyadhara.talya@xxxxxxxxx wrote:
> Have you declared the destructor and defined it even though it is empty
> ? Some times the vtable corruption happens if the destructor is declared
> and not defined.
> 
> Regards
> Vidya. 
> 
> -----Original Message-----
> From: Malte Witt [mailto:malte.witt@xxxxxxxxxxxxx] 
> Sent: Friday, June 29, 2007 4:42 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: 'Undefined reference to vtable' when inheriting from
> QObject
> 
> Are you sure, you are moc'ing your header files?
> Are you using qmake to build your Makefiles?
> 
> Usually this linker message happens whenever you forget to include the
> Q_OBJECT-Macro or you forget to moc your header files.
> 
> Regards,
> Malte
> 
> 
> 
> Declan McGrath <declanmcgrath@xxxxxxxxxxxx> schrieb am 29.06.2007
> 13:08:18:
> 
> > Hi folks,
> > 
> > Just trying to create a simple class called Browser composed of a 
> > QTextBrowser and a JsDomDocument (JsDomDocument inherits from 
> > QDomDocument).
> > 
> > Why would I be getting the following "undefined reference to vtable 
> > for Browser" error? I have the constructor in the .cpp file correctly
> declared in 
> > hte .h file - I think???
> > 
> > Thanks for any help,
> > Dec
> > 
> > 
> > 
> > 
> /mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
> : 
> > undefined reference to `vtable for Browser'
> > 
> /mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
> : 
> > undefined reference to `vtable for Browser'
> > 
> /mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:38
> : 
> > undefined reference to `vtable for Browser'
> > browser.o: In function `Browser':
> > 
> /mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34
> : 
> > undefined reference to `vtable for Browser'
> > 
> /mnt/extra/BackedUp/Projects/Subverted/frogface/trunk/src/browser.cpp:34
> : 
> > undefined reference to `vtable for Browser'
> > collect2: ld returned 1 exit status
> > gmake[1]: *** [../bin/frogface] Error 1
> > gmake: *** [sub-src-make_default] Error 2
> > *** Exited with status: 2 ***
> > 
> > 
> > *******************************************************************
> > browser.h
> > *******************************************************************
> > #ifndef BROWSER_H
> > #define BROWSER_H
> > 
> > #include <QTextBrowser>;
> > #include "jsdomdocument.h";
> > #include <QObject>
> > /**
> >    @author Declan McGrath <declanmcgrath@xxxxxxxxxxxx> */ class 
> > Browser : public QObject { Q_OBJECT
> > 
> > private:
> >     QTextBrowser& m_textBrowser;
> >     JsDomDocument m_domDoc;
> > 
> > public:
> >     Browser(QTextBrowser& textBrowser, QObject* parent = 0);
> >     ~Browser();
> > 
> > public slots:
> >     JsDomDocument document()
> >     { return m_domDoc; };
> > 
> >     void setXHtml(const QString& xhtml);
> >     QString toXHtml() const;
> > };
> > 
> > #endif
> > 
> > *******************************************************************
> > browser.cpp
> > *******************************************************************
> > #include "browser.h"
> > 
> > Browser::Browser(QTextBrowser& textBrowser, QObject* parent /*= 0*/)
> > :
> > m_textBrowser(textBrowser),
> > QObject(parent)
> > {
> > }
> > 
> > Browser::~Browser()
> > {
> > }
> > 
> > void Browser::setXHtml(const QString& xhtml) {
> >     m_domDoc.setContent(xhtml);
> >     m_textBrowser.setHtml(this->toXHtml());
> > }
> > 
> > QString Browser::toXHtml() const
> > {
> >     return m_domDoc.toString(2);
> > }
> > 
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> 
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> > 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
> 
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 
> 
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>  
> www.wipro.com
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part