2

In my project I'm using QImage to save a generated picture, but when 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.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
confusedKid
  • 3,231
  • 6
  • 30
  • 49

2 Answers2

2
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.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • 1
    Right. You need to link against the Qt library that has the definition of `QImage`. – James McNellis Apr 14 '11 at 02:48
  • Can you elaborate on how I can go about doing that? Thanks. – confusedKid Apr 14 '11 at 02:49
  • You need to look in the Qt documentation to find which library file that you need to link against and add that library to the "Additional Dependencies" under "Linker => General" in the Visual C++ Project Properties. Never having used Qt, I don't know what library you need. – James McNellis Apr 14 '11 at 02:53
1

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.

Community
  • 1
  • 1
confusedKid
  • 3,231
  • 6
  • 30
  • 49