I have Created a MainWindow with and Need to print the MainWindow (including all children).
How do I do this?
Are there any examples available?
Thanks
I have Created a MainWindow with and Need to print the MainWindow (including all children).
How do I do this?
Are there any examples available?
Thanks
I have created the MainWindow with this code
then used the print method as a slotQt Code:
ui(new Ui::MainWindow) { // MainWindow Constructor ui->setupUi(this); loadFile(); }To copy to clipboard, switch view to plain text mode
then errorQt Code:
264 void MainWindow::Print() 265 { 266 NotImplemented(); 267 268 QPrinter printer; 269 printer.setOutputFileName("Attenuation_Calculator.pdf"); 271 MainWindow.render(&printer); 272 273 }To copy to clipboard, switch view to plain text mode
C2143: syntax error : missing ';' before '.'
why...when the auto fill allows me to select .render as a method of MainWindow?
Last edited by anda_skoa; 12th April 2015 at 08:36. Reason: missing [code] tags
Do you have a member variable of your MainWindow class named "MainWindow"? If not, do you know C++? If the answers are "No" and "Yes", then you can probably figure out why line 271 won't compile.why...when the auto fill allows me to select .render as a method of MainWindow?
And learn to use [code ] & [/code ] tags to wrap the code lines when you post source code. (With no spaces after the word "code" in the square brackets).
I am new to C++ and Qt....trying very hard to get up to speed.
but I do not understand what you mean d_stranz..
do you have a reference or example of what you mean ?
There is no object named "MainWindow" in scope where that statement is. There is, however, a type called "MainWindow" so the compiler is expecting an explicit call to method in the MainWindow class, like "MainWindow::staticFunc();", or a declaration, like "MainWindow foobar;", and does not find one before the dot and generates and error. You want neither of these anyway.
Assuming you are trying to print the window corresponding to the object this code is executing in then you should be calling render() on "this" object, i.e:
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
ChrisW67,
When I use render(&printer);
this causes a LNK2019 error
Print method.jpg
as per the attachment.
does it make any difference that I am using a .ui file to create the mainwindow?
How do I overcome this problem ?
and allow the linking to the printersupport library?
And you make sure you run qmake to create an updated Makefile with the new library name.You add QT+=libraryname (e.g. printsupport) to your project file.
All,
I have added
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
#include <QPainter>
and I still get the same unresolved external symbol error.
I believe QPainter is required for the render method..is this correct?
What other libraries do I need to add?
unresolved symbol is a linker error, which means the compiler was already satisfied with the includes before.
Wysota's suggestion is to add the printing module to the project, i.e. editing the project file
Adding includes is not adding libraries. Adding includes makes the compiler aware of types and declarations.
Adding libraries, or in your case a Qt module, is done in the project file.
Cheers,
_
Thanks....this has fixed the link problem..
Now I have got to the program compiling and executing.
but when I use the action Print from the menu bar I get
"QPrintDialog: Cannot be used on non-native printers" error
in the Application Output Window of the IDE
Hope this is an easy fix...lol.
There is an easy fix...
One of the other threads had a comment that the Windows based machines do not handled pdf well.
So I changed the line
printer.setOutputFileName("Filename.pdf");
to
printer.setOutputFileName("Filename");
and the printdialog worked.
I made sure the print to file was not ticked...and whalla...(ozzie slang for great it worked)
a print of what I wanted worked.
Thankyou for the Help to all..it is very much appreciated.
Wait, if all you wanted was to send the output to a printer, not a file, then why did you call printer.setOutputFileName() in the first place?
Also, the documentation of QPrinter::setOutputFileName() specifically says what happens when the file name ends with ".pdf".
Bookmarks