One of the QImage constructors gives me a linker error, but another constructor doesn't?
In my project I'm using QImage to save a generated picture, but whe开发者_JAVA技巧n I call
QImage image(width, height, QImage::Format_RGB32);
the visual studio compiler is giving me linker errors:
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)
But if I replace the code above with just a:
QImage image();
I do not get any linker errors, and compiles fine.
What's wrong here? :(
Update: To try and make sure Qt was functional, I tried making a QString:
QString s("hello world");
and this worked properly.
QImage image();
This does not declare an object and does not call the default constructor. It declares a function named image
that has no parameters and returns a QImage
.
This would invoke the default constructor:
QImage image;
This will probably give you a linker error as well; make sure that you are linking against whatever library QImage
is defined in.
I found a hint to this problem at this link.
I fixed the problem by including the GUI library module in Qt Project Settings->Qt Modules.
精彩评论