[Solved] "undefined reference" is thrown when compiling a custom class inheriting from QWebPage



  • I'm trying to create a custom class that inherits from QWebPage. The compiler is finding a bunch of "undefined reference" that I have been unable to solve.

    The custom page's header looks like:

    @#ifndef CUSTOMPAGE_H
    #define CUSTOMPAGE_H
    #include <QtWebKit/QWebPage>

    class CustomPage : public QWebPage {
    Q_OBJECT
    public:
    CustomPage(QObject *parent = 0);
    };
    #endif // CUSTOMPAGE_H@

    And the custompage.cpp looks like:

    @#include "custompage.h"

    CustomPage::CustomPage(QObject *parent) : QWebPage(parent)
    {

    }
    @

    The resumed error messages:

    @custompage.o: In function `CustomPage':

    custompage.cpp:3: undefined reference to `_imp___ZN8QWebPageC2EP7QObject'

    custompage.cpp:3: undefined reference to `_imp___ZN8QWebPageC2EP7QObject'

    moc_custompage.o:moc_custompage.cpp:59: undefined reference to `_imp___ZN8QWebPage11qt_metacastEPKc'

    moc_custompage.o:moc_custompage.cpp:64: undefined reference to `_imp___ZN8QWebPage11qt_metacallEN11QMetaObject4CallEiPPv'

    moc_custompage.o: In function `_static_initialization_and_destruction_0':

    moc_custompage.cpp:43: undefined reference to `_imp___ZN8QWebPage16staticMetaObjectE'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x1c): undefined reference to `QWebPage::event(QEvent*)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x38): undefined reference to `QWebPage::triggerAction(QWebPage::WebAction, bool)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x3c): undefined reference to `QWebPage::extension(QWebPage::Extension, QWebPage::ExtensionOption const*, QWebPage::ExtensionReturn*)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x40): undefined reference to `QWebPage::supportsExtension(QWebPage::Extension) const'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x44): undefined reference to `QWebPage::createWindow(QWebPage::WebWindowType)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x48): undefined reference to `QWebPage::createPlugin(QString const&, QUrl const&, QStringList const&, QStringList const&)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x4c): undefined reference to `QWebPage::acceptNavigationRequest(QWebFrame*, QNetworkRequest const&, QWebPage::NavigationType)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x50): undefined reference to `QWebPage::chooseFile(QWebFrame*, QString const&)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x54): undefined reference to `QWebPage::javaScriptAlert(QWebFrame*, QString const&)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x58): undefined reference to `QWebPage::javaScriptConfirm(QWebFrame*, QString const&)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x5c): undefined reference to `QWebPage::javaScriptPrompt(QWebFrame*, QString const&, QString const&, QString*)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x60): undefined reference to `QWebPage::javaScriptConsoleMessage(QString const&, int, QString const&)'

    moc_custompage.o:moc_custompage.cpp:(.rdata$_ZTV8CustomPage[vtable for CustomPage]+0x64): undefined reference to `QWebPage::userAgentForUrl(QUrl const&) const'

    moc_custompage.o: In function `~CustomPage':

    custompage.h:6: undefined reference to `_imp___ZN8QWebPageD2Ev'

    custompage.h:6: undefined reference to `_imp___ZN8QWebPageD2Ev'

    collect2: ld returned 1 exit status@

    I have been looking on google and on this forum but could not find a similar problem. It seems I'm missing a bunch of includes (for QWebPage and QObject) but I already tried to add them without any luck.

    What am I doing wrong?

    Thanks, it's my first QT project.



  • You forgot to implement the destructor.



  • Put it in your cpp file and it should compile well
    @CustomPage::~CustomPage()
    {
    }@

    hum, after reading your error message I've realized that your code is not the same code of the error message.
    Probably, on that situation, you've forgot to implement the event() and the triggerAction() methods too.



  • I will implement all the mentioned methods and let you know.
    Is it mandatory to implement all virtual methods?

    Thank you Danilo!



  • No, you just need to implement the methods defined on your .h file.



  • I updated my question. I only left the constructor inside the .h file but the compiler still complains about the missing implementations for all virtual methods.

    I'm using the Qt Creator on a windows vista box.

    Am I missing something obvious here?

    Thanks for your time.



  • Can you try to make a clean build?

    Your code compiles fine on linux...



  • Ah, of course...

    You forgot to include webkit module in your .pro file =)

    try this:

    QT += webkit



  • For the next time:

    use only <QWebPage> instead of <Webkit/QWebPage>

    It will warn you correctly if you forget to include the module, saying "the file QWebPage couldn't be found".

    And that should fix your problem, afaik.



  • Wooow, the: "QT += webkit" did the trick, I can compile the all project now! :)

    Thank you so much for your time! It was really really appreciated!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.