其中一个 QImage 构造函数给了我一个链接器错误,但另一个构造函数没有?
One of the QImage constructors gives me a linker error, but another constructor doesn't?
在我的项目中,我使用QImage来保存生成的图片,但当我调用时
QImage image(width, height, QImage::Format_RGB32);
visualstudio编译器给了我链接器错误:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QImage::~QImage(void)" (__imp_??1QImage@@UAE@XZ) referenced in function "void __cdecl lightTracer(void)" (?lightTracer@@YAXXZ)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QImage::QImage(int,int,enum QImage::Format)" (__imp_??0QImage@@QAE@HHW4Format@0@@Z) referenced in function "void __cdecl lightTracer(void)" (?lightTracer@@YAXXZ)
但如果我用替换上面的代码
QImage image();
我没有得到任何链接器错误,并且编译得很好。
这里出了什么问题?:(
更新:为了确保Qt正常工作,我尝试制作一个QString:
QString s("hello world");
这样做效果很好。
QImage image();
这不会声明对象,也不会调用默认构造函数。它声明了一个名为image
的函数,该函数没有参数,并返回一个QImage
。
这将调用默认构造函数:
QImage image;
这可能也会给你一个链接器错误;请确保您链接的是在.
中定义的任何库QImage
我在这个链接上发现了这个问题的提示。
我通过在Qt项目设置->Qt模块中包含GUI库模块来解决这个问题。
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 构造函数正在调用一个使用当前类类型的函数
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 构造函数在退出函数时无法初始化一个参数
- C++-我可以创建另一个类的成员并在构造函数中使用它吗
- 为什么需要知道一个类是平凡的还是有平凡的构造函数
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 关于复制构造函数的一个棘手问题
- 没有公共构造函数作为另一个类模板成员的类模板
- C++:将初始化的对象传递给另一个类的构造函数;需要不必要的构造函数吗?
- 将另一个类的对象传递到当前类C++的构造函数中(不是成员初始化)
- 如何将我编写的对象传递到另一个类的构造函数中?
- 如何使用 swig 修改类构造函数以保留对其中一个构造函数参数的引用?
- C++:调用没有匹配函数:为什么需要一个空的构造函数?
- 在C++中将对象从另一个类传递到另一个类的构造函数?
- 为什么从另一个构造函数内部调用C++构造函数不修改类变量?
- 创建一个没有复制构造函数的类的 std::vector 的 std::vector
- 在 C++ 中声明 const 对象需要用户定义的默认构造函数.如果我有一个可变成员变量,为什么不呢?
- 在c++中的复制构造函数/一个声明语句中的初始化的延续中使用chain方法