سؤال

[Solved]This problem somehow resolved itself on about the 5-6 clean and rebuild, no code was changed

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

from another class i am trying to call the constructor and pass 8 parameters however when i try to do this i am getting a LNK2019 Error.

The thing thats confusing me though is if i call the default constructor nothing the program compiles and runs fine... everything has the correct includes and must be working because i can call the default constructor, i am using QStrings as some of the arguments but QString is included so it cant be that... any other reason anyone knows of why i would geta LNK2019 error for a constructor taking arguments and not when its the default one??

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 have just removed context and values etc but makes no difference on 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();
}

FULL 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)
هل كانت مفيدة؟

المحلول

I know this is a really late response but I struggled for a long time with the same issue.

QT doesn't always parse the c++ files correctly when doing a clean->rebuild. Luckily to force it to do so just manually delete the build files and it will run from scratch.

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

نصائح أخرى

Have you tried to rebuild the project? In some circumstance this really can produce linkage errors similar like you described.

Okay, could you please copy paste the same code as you have in your project? :)

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

Here, for example, you can't name instance of "car" with the same name. You should use another identifier, for example:

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

I was facing the same issue and none of the suggested answers worked for me. Eventually running qmake did the trick for me.

  1. Right click project name
  2. Run qmake
  3. Clean
  4. Rebuild

I thought this might help someone who's facing similar issue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top