QPrinter, QPrintDialog giving errors not encountered in code examples
Posted
by
karunesh
on Stack Overflow
See other posts from Stack Overflow
or by karunesh
Published on 2011-06-21T08:18:11Z
Indexed on
2011/06/21
8:23 UTC
Read the original article
Hit count: 621
qt
In the imageviewer example, QPainter and QPrintDialog objects are defined and used as following:
#ifndef QT_NO_PRINTER
QPrinter printer;
#endif
and
QPrintDialog dialog(&printer, this);
A QPainter object is then initialized with QPrinter (printer).
When I tried to use the same code in my function, it looks like:
void imageviewer::print()
{
...
#ifdef QT_NO_PRINTER
QPrinter printer(this); //ERROR 1
QPrintDialog dialog(&printer, this);//ERROR 2 and 3
if (dialog.exec()) //ERROR 4
{
//do the painting
}
#endif
}
The errors are:
1. variable 'QPrinter printer' has initializer but incomplete type
2. 'QPrintDialog' was not declared in this scope
3. Expected ';' before 'dialog'
4. 'dialog' was not declared in this scope
What I am notable to understand is why are these errors arising when I am using them in my code, but not in the example.
As a friend pointed out, I made sure that I used the right #include files and made sure that 'printer' and 'dialog' were not touched anywhere else in the example.
© Stack Overflow or respective owner