Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/Qt unresolved external when calling constructor

[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)
like image 950
AngryDuck Avatar asked Apr 12 '13 10:04

AngryDuck


1 Answers

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!

like image 189
user2448431 Avatar answered Sep 21 '22 23:09

user2448431