‘QPainter painter’ has initialiser but incomplete type

If you ever got an error something like [some-class] has initialiser but incomplete type, it basically means the compiler cannot understand the type and you need to add the include for it.

QPixmap pixmap(20,10);
pixmap.fill(Qt::white);

QPainter painter(&pixmap);
QPen pen(Qt::blue);

Take the code snipped above when you compile it you might get an error something along the lines of the following for line 4.

‘QPainter painter’ has initialiser but incomplete type

To fix this you need to include the header file where QPainter is defined. The updated code looks like:

#include <qpainter.h>

QPixmap pixmap(20,10);
pixmap.fill(Qt::white);

QPainter painter(&pixmap);
QPen pen(Qt::blue);

Published by

Amit Bahree

This blog is my personal blog and while it does reflect my experiences in my professional life, this is just my thoughts. Most of the entries are technical though sometimes they can vary from the wacky to even political – however that is quite rare. Quite often, I have been asked what’s up with the “gibberish” and the funny title of the blog? Some people even going the extra step to say that, this is a virus that infected their system (ahem) well. [:D] It actually is quite simple, and if you have still not figured out then check out this link – whats in a name?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: