Qt,不能在窗口的构造函数中实例化对象吗?
Qt, cannot instantiate an object in a window's constructor?
如何在窗口的构造函数中创建对象的实例? 我通过在"window.h"中声明一个指针(命名对象)并在"窗口.cpp:"窗口中::窗口(...)"中实例化它来生成三个错误{...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)
debugPhursik.exe:-1: error: LNK1120: 2 unresolved externals
我查找了错误,显然它们与正在声明但未由类定义的函数有关。 我敢肯定;但是,在"objectHandler.h"中声明的所有函数都是在"objectHandler.cpp"中定义的,Qt Creator甚至知道如何从另一个函数中找到一个函数。 我很困惑,所以提前感谢您的帮助。
从窗口.cpp
Window::Window(QWidget *parent) :
QWidget(parent),
ui(new Ui::Window)
{
...
objects = new objectHandler(STEP_TIME_HOURS);
ui->setupUi(this);
}
从窗口.h
namespace Ui {
class Window;
}
class Window : public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
~Window();
...
从对象处理程序.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;
}...
来自对象处理程序.h
class objectHandler
{
public:
objectHandler(int stepTimeHours);
~objectHandler();
...
largeBody *head, *current, *tail;
}
我解决了。 下面的问题类似,除了 QT Creator 自动将我的".h"文件添加到 .pro 文件中的列表中。 我只需要删除构建文件夹,突然一切都开始工作。
为什么Qt Creator在包含的路径中找不到包含的标头 - 即使qmake能够找到它们
相关文章:
- 为什么我不能引用指向实例化对象的函数的指针?
- 为什么在使用指针时不采用类成员的默认值,而不是直接实例化对象时?
- 实例化对象并调用方法,使用单行语法在 C# 或 C++ 中返回值?
- 为什么我不能更改实例化对象内部的向量?
- 为共享指针C++单独实例化对象
- 错误 C2280 / 在 std::vector 中实例化对象时复制构造函数出现问题?
- C++:我可以在 void 函数中实例化对象吗?
- 为什么当我在构造函数中创建线程时,实例化对象和对象的指针的行为不同
- 是否可以由于以下原因在堆中实例化对象
- 一类应管理其实例化对象
- 实例化对象时如何修复分段故障错误
- QML实例化C 对象.我如何访问他们的方法
- 如何在 c++ 中使用枚举参数实例化对象
- C 实例化对象,在没有指针的情况下,其他类构造函数中没有默认构造函数
- 用push_back()实例化对象时,如何将指针传递给对象的构造函数
- 我如何在C 类的内部实例化对象
- 两者之间的最佳方法是什么:实例化对象或使用指针
- 从标头中的类实例化对象
- 我能否获得一个C++编译器在编译时实例化对象
- 访问不带实例化对象的非静态成员函数