1

I may be missing something obvious, but I can't get rid of a linking error in my Qt user interface.

I've isolated the part that's causing trouble. Basically, I'm implementing a subclass of QGraphicsView to display an interactive overhead map. For some reason, I can't get the constructor to be resolved.

OverheadMap.h :

#ifndef OVERHEADMAP_H
#define OVERHEADMAP_H

#include <QGraphicsView>

class OverheadMap : public QGraphicsView {
    Q_OBJECT

public:
    OverheadMap();
};

#endif // OVERHEADMAP_H

OverheadMap.cpp :

#include "OverheadMap.h"

OverheadMap::OverheadMap() {
    // Body
}

main.cpp :

#include "OverheadMap.h"

int main(int argc, char *argv[])
{
    OverheadMap *map = new OverheadMap();
}

LNK2019 :

main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall OverheadMap::OverheadMap(void)" (??0OverheadMap@@QAE@XZ) referenced in function _main

I can without any trouble use QtCreator's auto-completion with OverheadMap, and I have done a similar subclass implementation of a QFrame that's working, so I doubt there's a syntax error here.

What am I missing?

Thanks.

Alexis Leclerc
  • 1,303
  • 1
  • 16
  • 26
  • And the file `OverheadMap.cpp` is in your project and is being built? – Some programmer dude Jul 17 '14 at 16:47
  • Make sure you have re-built the Qt generated files for your project. Any new class won't understand Qt syntax like Q_OBJECT until they have their own files. – Lochemage Jul 17 '14 at 16:50
  • `OverheadMap.cpp` is in the source folderlike every other .cpp files I've created, and I've tried cleaning/rebuilding at least 10 times. I've even tried closing/reopening QtCreator. – Alexis Leclerc Jul 17 '14 at 16:53
  • I was probably too quick, but can you provide an SSCCE? If it seems to be a different issue with an SSCCE, I will reopen it. – László Papp Jul 17 '14 at 16:59
  • Is the file in the source folder of QtCreator, in the source folder on disk? If it's only on disk, there's nothing to tell QtCreator that it should use it. – Some programmer dude Jul 17 '14 at 17:01
  • @JoachimPileborg In the source folder of QtCreator, along with my other working source files. – Alexis Leclerc Jul 17 '14 at 17:04
  • 1
    And if you check the build log, you see that it's actually built without errors or warnings? – Some programmer dude Jul 17 '14 at 17:06
  • @FinalContest This is already a shortened example of my code. I'm confused as to what I have to change for the superclass constructor call. Isn't the empty constructor called by default? – Alexis Leclerc Jul 17 '14 at 17:07
  • 1
    @AlexisLeclerc: where is your project file? Unfortunately, I cannot reproduce this issue on Linux at least. Your code works fine for me, but I reopened for you anyway. Not that you should throw the Qt parent/children mechanism away. – László Papp Jul 17 '14 at 17:10
  • @JoachimPileborg I did check the logs, and `OverheadMap.cpp` was indeed (for some reason) not compiled. I ran a qmake and now everything builds fine! I did not know qmake takes care of the build path. – Alexis Leclerc Jul 17 '14 at 17:16
  • 2
    Thanks for your time and help guys, now my full code works. All I was missing is a stupid qmake to restablish the build path! – Alexis Leclerc Jul 17 '14 at 17:23

2 Answers2

0

You need to call your base class's constructor

OverheadMap::OverheadMap() : QGraphicsView()
{
    // Body
}
M__
  • 71
  • 1
  • 9
0

This code works just fine for me.

So, the solution is that you have to re-run qmake because based on your comments, you modified the project structure without telling that to qmake.

László Papp
  • 51,870
  • 39
  • 111
  • 135