Reputation: 105
How do I create an instance of an object in the constructor for a window? I am generating three errors just by declaring a pointer, named objects, in 'window.h' and instantiating it in 'window.cpp:' 'Window::Window(...){...objects = new objectHandler(1)}'
window.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall objectHandler::objectHandler(int)" (??0objectHandler@@QAE@H@Z) referenced in function "public: __thiscall Window::Window(class QWidget *)" (??0Window@@QAE@PAVQWidget@@@Z)
(file not found)
window.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall objectHandler::~objectHandler(void)" (??1objectHandler@@QAE@XZ) referenced in function "public: void * __thiscall objectHandler::`scalar deleting destructor'(unsigned int)" (??_GobjectHandler@@QAEPAXI@Z)
(file not found)
debug\Phursik.exe:-1: error: LNK1120: 2 unresolved externals
I looked up the errors and apparently they have to do with the functions being declared but not defined by the class. I am sure; however, that all functions declared in 'objectHandler.h' are defined in 'objectHandler.cpp' and Qt Creator even knows how to find one from the other. I am quite perplexed so thank you for your help in advance.
From window.cpp
Window::Window(QWidget *parent) :
QWidget(parent),
ui(new Ui::Window)
{
...
objects = new objectHandler(STEP_TIME_HOURS);
ui->setupUi(this);
}
From window.h
namespace Ui {
class Window;
}
class Window : public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
~Window();
...
From objecthandler.cpp
objectHandler::objectHandler(int stepTimeHours)
{
this->stepTimeHours = stepTimeHours;
head = nullptr;
current = nullptr;
tail = nullptr;
}
objectHandler::~objectHandler()
{
current = head;
if (current->next)
{
current = current->next;
delete current->last;
}
else if (current)
delete current;
}...
From objecthandler.h
class objectHandler
{
public:
objectHandler(int stepTimeHours);
~objectHandler();
...
largeBody *head, *current, *tail;
}
Upvotes: 1
Views: 1170
Reputation: 105
I solved it. The issue below is similar except QT Creator automagically added my '.h' files to the list in the .pro file. I just needed to delete the build folder and suddenly everything started working.
Upvotes: 1