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
QtWS25 Last Chance

Undefined reference to vtable error

Scheduled Pinned Locked Moved General and Desktop
vtableqgraphicsrectit
10 Posts 4 Posters 4.0k Views
  • 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #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
      0
      • mrjjM mrjj

        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 last edited by nanoandrew4
        #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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          0
          • SGaistS SGaist

            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 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
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on 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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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
                • hskoglundH hskoglund

                  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 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
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 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 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

                      • Login

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