C ++ / Qt unresolved external when calling constructor

[SOLVED] This problem was somehow resolved around 5-6 clean and rebuilt, the code was not changed

I have a class with a standard constructor and a constructor that takes 8 arguments.

from another class, I try to call the constructor and pass 8 parameters, however, when I try to do this, I get LNK2019 Error .

The thing that baffles me is that if I call the default constructor, it compiles nothing and works fine ... everything has the correct values ​​and should work, because I can call the default constructor, I use QStrings as some of the arguments, but QString is included, so it cannot be like that ... any other reason why anyone knows why I would like to geta LNK2019 Error for a constructor that takes arguments, and not when its default value:

Car.h

 #include <QString> class car { public: car(); car(int car_id, QString something, QString something_else, QString something3, int an_int, int another_int, int another_int_i, QString something4); }; 

car.cpp

 car::car() { } car::car(int car_id, QString something, QString something_else, QString something3, int an_int, int another_int, int another_int_i, QString something4) { } 

Obviously, I just deleted the context and values, etc., but has no meaning to the structure

DatabaseController.cpp

 #include "DatabaseController.h" #include "car.h" void DatabaseController::DoSomething() { car *pcar = new car(0, "", "", "", 0, 0, 0, ""); } 

interface.cpp

 #include "DatabaseController.h" void interface::on_btn_clicked() { DatabaseController DC; DC.DoSomething(); } 

TOTAL ERROR:

 DatabaseController.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall car::car(int,class QString,class QString,class QString,int,int,int,class QString)" ( ??0car@ @ QAE@HVQString @@ 00HHH0@Z ) referenced in function "public: void __thiscall DatabaseController::getAll(class QString)" ( ?getAll@DatabaseController @@ QAEXVQString@ @@Z) 
+6
source share
3 answers

I know this is a very late answer, but I struggled with the same problem for a long time.

QT does not always correctly parse C ++ files when doing clean-> rebuild. Fortunately, to get this done, simply manually delete the assembly files and it will work from scratch.

It worked for me and I hope this helps a few people!

+9
source

Did you try to rebuild the project? In some circumstances, this can actually lead to clutch errors similar to those described by you.

Ok, could you copy the insert the same code as in your project? :)

 car *car = new car(0, "", "", "", 0, 0, 0, ""); 

Here, for example, you cannot name an instance of a β€œcar” with the same name. You must use a different identifier, for example:

 car *pCar = new car(0, "", "", "", 0, 0, 0, ""); 
+2
source

I ran into the same problem and none of the suggested answers worked for me. In the end, qmake worked.

  • Right-click project name
  • Run qmake
  • Clear
  • Rebuild

I thought this could help someone who is facing a similar problem.

+1
source

All Articles