Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [Solved] "undefined reference" is thrown when compiling a custom class inheriting from QWebPage
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Qt WebKit
10 Posts 2 Posters 11.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jdecuyper
    wrote on 13 Oct 2010, 17:22 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on 13 Oct 2010, 20:15 last edited by
      #2

      You forgot to implement the destructor.

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • D Offline
        D Offline
        danilocesar
        wrote on 13 Oct 2010, 20:19 last edited by
        #3

        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.

        <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
        Software Engineer

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jdecuyper
          wrote on 13 Oct 2010, 21:17 last edited by
          #4

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

          Thank you Danilo!

          1 Reply Last reply
          0
          • D Offline
            D Offline
            danilocesar
            wrote on 13 Oct 2010, 21:28 last edited by
            #5

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

            <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
            Software Engineer

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jdecuyper
              wrote on 13 Oct 2010, 22:09 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                danilocesar
                wrote on 13 Oct 2010, 23:24 last edited by
                #7

                Can you try to make a clean build?

                Your code compiles fine on linux...

                <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                Software Engineer

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  danilocesar
                  wrote on 13 Oct 2010, 23:25 last edited by
                  #8

                  Ah, of course...

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

                  try this:

                  QT += webkit

                  <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                  Software Engineer

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    danilocesar
                    wrote on 13 Oct 2010, 23:33 last edited by
                    #9

                    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.

                    <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                    Software Engineer

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jdecuyper
                      wrote on 14 Oct 2010, 00:17 last edited by
                      #10

                      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!

                      1 Reply Last reply
                      0

                      1/10

                      13 Oct 2010, 17:22

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved