Development/Tutorials/Printing Hello World: Difference between revisions
< Development | Tutorials
Midnighter (talk | contribs) (Undo revision 38831 by Midnighter (Talk)) |
No edit summary |
||
Line 1: | Line 1: | ||
== The mission == | |||
Print '''Hello World''' on your printer. | Print '''Hello World''' on your printer. | ||
=The | == The code == | ||
= | |||
<code cppqt n> | <code cppqt n> | ||
#include <qpainter.h> | #include <qpainter.h> | ||
#include <qprinter.h> | |||
#include <kapplication.h> | #include <kapplication.h> | ||
#include <kaboutdata.h> | #include <kaboutdata.h> | ||
Line 22: | Line 18: | ||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
KAboutData aboutData( "test", "test", "1.0", "test", | |||
KAboutData::License_GPL, "(c) 2006" ); | |||
KCmdLineArgs::init( argc, argv, &aboutData ); | |||
KApplication app; | |||
QPrinter printer; | |||
printer.setFullPage(true); | |||
QPainter painter; | QPainter painter; | ||
painter.begin( & | painter.begin(&printer); | ||
painter.drawText(100,100,"Hello World"); | painter.drawText(100,100,"Hello World"); | ||
painter.end(); | painter.end(); | ||
// this makes the print job start | // this makes the print job start | ||
} | } | ||
</code> | </code> | ||
= | == How to compile == | ||
=== CMakeLists.txt === | |||
<code> | <code> | ||
find_package(KDE4 REQUIRED) | find_package(KDE4 REQUIRED) | ||
include_directories( ${KDE4_INCLUDES} ) | include_directories( ${KDE4_INCLUDES} ) | ||
kde4_add_executable(printhelloworld printtest.cpp) | kde4_add_executable(printhelloworld printtest.cpp) | ||
target_link_libraries(printhelloworld ${ | target_link_libraries(printhelloworld ${${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY}) | ||
</code> | </code> | ||
===Make and Run=== | |||
=== Make and Run === | |||
Then do: | Then do: | ||
cmake . | cmake . | ||
Line 58: | Line 51: | ||
./printhelloworld | ./printhelloworld | ||
[[Category:KDE4]] | [[Category:KDE4]] | ||
[[Category:C++]] | [[Category:C++]] |
Revision as of 12:11, 27 May 2011
The mission
Print Hello World on your printer.
The code
- include <qpainter.h>
- include <qprinter.h>
- include <kapplication.h>
- include <kaboutdata.h>
- include <kmessagebox.h>
- include <kcmdlineargs.h>
/*
This prints Hello World on your printer
- /
int main(int argc, char *argv[])
{
KAboutData aboutData( "test", "test", "1.0", "test",
KAboutData::License_GPL, "(c) 2006" );
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication app;
QPrinter printer;
printer.setFullPage(true);
QPainter painter;
painter.begin(&printer);
painter.drawText(100,100,"Hello World");
painter.end();
// this makes the print job start
}
How to compile
CMakeLists.txt
find_package(KDE4 REQUIRED)
include_directories( ${KDE4_INCLUDES} )
kde4_add_executable(printhelloworld printtest.cpp)
target_link_libraries(printhelloworld ${${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY})
Make and Run
Then do:
cmake . make ./printhelloworld