Qprinter Is there a simple Hello World example
Hi I just started learning QT.
My background in programming goes back to writing assembly programs for commodore. Wrote a lot of programs using Clipper now using Flagship for compiling my old XBase code.
I also do C programming for creating software for Atmel chips using CodeVisionAVR
So I have finally started to migrate into the OOPS realm and i think I making some good progress however the Qprinter is really stumping me. All night trying to figure out the example fontsampler.pro in QT 5.5 using Creator 3.4.2. It's the only example I have found so far using qprinter
I have been learning from VoidRealms videos but I have not found one on printing yet.
In clipper I would just use this code to redirect output to the default printer:
set print on
@ prow(),pcol() say "hello world"
set print off
Of course that was when LPT ports had printers attached.
Flagship was a bit more complicated allowing user to select printer and options like Qprinter classes but i am really stumped at the moment.
So a little help here will go a long way.
@metron9 In QtCreator click Welcom > Examples > Text Edit. This is a Qt widget main application for text editing and printing (printer and pdf). You can also play around with fonts. Good luck.
Thanks for the information.
I am trying to break down the textedit example. I am trying to delete one by one all of the code that is not used to print. I'm learning how and where things get connected by removing and changing lines of code along with qDebug.
So I commented out the code in textedit.cpp
// void TextEdit::textBold()
// QTextCharFormat fmt;
// fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
Compiling I double click on the error
C:\Qt\Examples\Qt-5.5\widgets\richtext\build-textedit-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\moc_textedit.cpp:151: error: undefined reference to `TextEdit::textBold()'
and it opens moc-textedit.cpp
where the case 7: line calls textBold()
Can you tell me is moc-textedit a QT generated file or where it comes from?
Not sure why its outside the project.
How would you go about deleting the Bold button or any other button in this code?
Hi and welcome to devnet,
moc is the Meta Object Compiler and will generate these moc files for you when you create QObject derived class that contains the Q_OBJECT macro (needed for signals and slots).
As for your problem, textBold is a slot and thus needs an implementation so you should either comment only the code in the body of the function or also comment the function declaration in textedit.h
@SGaist Thanks I commented out the Qaction and the function prototype and the declaration and body as well as calls to that function.
I'm on my way now. It's kind of like taking apart a piece of hardware to see how it works, just looking at it or reading it simply does not sink in.
I'm going to explore the debugger and how to use it tonight.
Ill be back....
Finally it starts to sink in.
I have put up my work in process program on Github
I named it AsapOrderForm
There are extra buttons I am experimenting with for saving file and other code
I have found.
Anyway, This program will have an input form not implemented yet and do the following.
- Print the form
- Create a PDF
- email the form
Have not looked at how to implement the email part yet.
Hope new programmers can find some of the code useful.