Qt,不能在窗口的构造函数中实例化一个对象?

Qt, cannot instantiate an object in a window's constructor?

如何在窗口的构造函数中创建对象的实例?我只是通过在“window.h”中声明一个名为对象的指针并在“window.cpp:”中实例化它来生成三个错误 'Window::Window(...){...objects =新对象处理器(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

我查找了错误,显然它们与类声明但未定义的函数有关。我确定;但是,在“objectHandler.h”中声明的所有函数都在“objectHandler.cpp”中定义,Qt Creator 甚至知道如何从另一个中找到一个。我很困惑所以提前感谢你的帮助。

来自 window.cpp

Window::Window(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Window)
{
...
    objects = new objectHandler(STEP_TIME_HOURS);
    ui->setupUi(this);
}

来自 window.h

namespace Ui {
class Window;
}

class Window : public QWidget
{
    Q_OBJECT

public:
    explicit Window(QWidget *parent = 0);
    ~Window();
...

来自 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;
}...

来自 objecthandler.h

class objectHandler
{
public:
    objectHandler(int stepTimeHours);
    ~objectHandler();
...
    largeBody *head, *current, *tail;
}

我解决了。除了 QT Creator 自动将我的“.h”文件添加到 .pro 文件的列表之外,下面的问题是类似的。我只需要删除构建文件夹,突然一切都开始工作了。

Why doesn't Qt Creator find included headers in included paths - even though qmake is able to find them