Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Undefined reference to vtable error
Forum Updated to NodeBB v4.3 + New Features

Undefined reference to vtable error

Scheduled Pinned Locked Moved General and Desktop
vtableqgraphicsrectit
10 Posts 4 Posters 4.1k Views 3 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.
  • N Offline
    N Offline
    nanoandrew4
    wrote on 4 Oct 2015, 21:02 last edited by
    #1

    I was building a program as I usually do, but for some reason, I can't get beyond this error. Here is my code:
    http://pastebin.com/YfKc0McZ - Player.h
    http://pastebin.com/Ucm0uByn - Player.cpp

    Any ideas on why this happens?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 4 Oct 2015, 21:04 last edited by mrjj 10 Apr 2015, 21:06
      #2

      ahh, add Q_OBJECT to your object ?

      like
      class MainWindow : public QMainWindow
      {
      Q_OBJECT
      ..

      then clean and rebuild all.

      N 1 Reply Last reply 4 Oct 2015, 21:15
      0
      • M mrjj
        4 Oct 2015, 21:04

        ahh, add Q_OBJECT to your object ?

        like
        class MainWindow : public QMainWindow
        {
        Q_OBJECT
        ..

        then clean and rebuild all.

        N Offline
        N Offline
        nanoandrew4
        wrote on 4 Oct 2015, 21:15 last edited by nanoandrew4 10 Apr 2015, 21:17
        #3

        @mrjj Thanks for the quick answer! I don't recall needing that, but when I add it, the whole thing gets worse with it complaining about protected classes and such.
        EDIT: In my previous game, it was exactly like that and there was no problem

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Oct 2015, 21:18 last edited by
          #4

          Hi,

          When adding/removing Q_OBJECT you need to re-run qmake before building, or do a full clean build.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply 4 Oct 2015, 21:20
          0
          • S SGaist
            4 Oct 2015, 21:18

            Hi,

            When adding/removing Q_OBJECT you need to re-run qmake before building, or do a full clean build.

            N Offline
            N Offline
            nanoandrew4
            wrote on 4 Oct 2015, 21:20 last edited by
            #5

            @SGaist I have been trying that several times now, clean all, run qmake and build, but it still outputs the same thing. Thanks for the suggestion tho!

            1 Reply Last reply
            0
            • H Online
              H Online
              hskoglund
              wrote on 4 Oct 2015, 21:21 last edited by
              #6

              Hi, you get the vtable error because you're declaring keyPressEvent in your Player class, and that method is from QWidget. So either you also inherit from QWidget or move that method to some other class that also inherits from QWidget...

              N 1 Reply Last reply 4 Oct 2015, 21:25
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 4 Oct 2015, 21:23 last edited by
                #7

                To add to @hskoglund you have QGraphicsObject if you need QObject features

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • H hskoglund
                  4 Oct 2015, 21:21

                  Hi, you get the vtable error because you're declaring keyPressEvent in your Player class, and that method is from QWidget. So either you also inherit from QWidget or move that method to some other class that also inherits from QWidget...

                  N Offline
                  N Offline
                  nanoandrew4
                  wrote on 4 Oct 2015, 21:25 last edited by
                  #8

                  @hskoglund By inhereting from QWidget I get the same error 3 times. Also, my last project inherited from QGraphicsPixmapItem and had no problem when the code was like this. Any ideas why?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 4 Oct 2015, 21:27 last edited by
                    #9

                    sorry my bad, I read it as QWidget.
                    Not sure you need Q_OBJECT for QGraphicsRectItem

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nanoandrew4
                      wrote on 5 Oct 2015, 02:05 last edited by
                      #10

                      Deleted the project, ran it on the laptop and everything seems fine now... I will look into it to see what the issue was, maybe there is something missing somewhere

                      1 Reply Last reply
                      0

                      1/10

                      4 Oct 2015, 21:02

                      • 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