0

I would like to use a class from one Qt project (A) in another (B). I am able to successfully include the .h file from A in B, and build project B. However, when I try to create an object declared in the .h file in B, I get a link error (Unresolved External Symbol). Can I do what I am trying to do, and if so how? I have tried using include() in my B.pro file, but get compile errors. The link error is the farthest I have gotten (with no changes to my .pro file).

In B's main.cpp file I have: #include "../A/testymctestface.h"

In the main I try to create an object of the included class:

TestyMcTestFace test;

This is when I get the link error.

testymctestface.h contains:

class TestyMcTestFace{
public:
    TestyMcTestFace();
};

testymctestface.cpp contains:

#include "testymctestface.h"

TestyMcTestFace::TestyMcTestFace(){

}
galactikuh
  • 765
  • 8
  • 18
  • You need to add the .cpp into the second project as well, not just the header file (.h). – john elemans Aug 26 '16 at 19:57
  • @johnelemans do you mean in the SOURCES part of the .pro file? If I do that I get this error... :-1: warning: C:/Users/Pack/Documents/Projects/TestImport/main.cpp conflicts with C:/Users/Pack/Documents/Projects/DataScatter/main.cpp – galactikuh Aug 26 '16 at 20:03
  • Not all the sources, just the class that you wish to use. (like testyMcTestFace.cpp in your example) – john elemans Aug 26 '16 at 20:04
  • That's all I'm doing.. My pro file... SOURCES += main.cpp\ widget.cpp \ scattermodifier.cpp \ KMeans.cpp \ Point.cpp \ ../TestImport/testymctestface.cpp HEADERS += widget.h \ scattermodifier.h \ KMeans.h \ Point.h \ ../TestImport/testymctestface.h – galactikuh Aug 26 '16 at 20:05
  • Well, that should work. You don't have testImport/main.cpp in there, so it should not be possible to create the conflict. Run qmake. – john elemans Aug 26 '16 at 20:14
  • That's what gives me the error :( – galactikuh Aug 26 '16 at 20:16
  • Oh! Tricky. I had to CLEAN and then run qmake. Thanks for your help.. – galactikuh Aug 26 '16 at 20:19

0 Answers0