Development/Tutorials/Printing Hello World (ru): Difference between revisions
Midnighter (talk | contribs) (New page: {{note|This tutorial seems not to be up to date with current KDE4 development.}} =The mission= Print '''Hello World''' on your printer. =The KDE version= This code will work for KDE 3 as...) |
Midnighter (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
{{Template:I18n/Language Navigation Bar|Development/Tutorials/Printing_Hello_World}} | |||
{{note|This tutorial seems not to be up to date with current KDE4 development.}} | {{note|This tutorial seems not to be up to date with current KDE4 development.}} | ||
Revision as of 22:49, 21 February 2009
Development/Tutorials/Printing_Hello_World
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
The mission
Print Hello World on your printer.
The KDE version
This code will work for KDE 3 as for KDE 4.
The code
- include <kprinter.h>
- include <qpainter.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;
KPrinter job;
job.setFullPage( true );
if ( job.setup() )
{
QPainter painter;
painter.begin( &job );
painter.drawText(100,100,"Hello World");
painter.end();
// this makes the print job start
}
}
Explanation
You need a KDE instance to print, because this instance stores your configuration, including your printer configuration. You create one by instanciating the KApplication class.
How to compile
With KDE 4 and CMake
CMakeLists.txt
find_package(KDE4 REQUIRED)
include_directories( ${KDE4_INCLUDES} )
kde4_add_executable(printhelloworld printtest.cpp)
target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})
Make and Run
Then do:
cmake . make ./printhelloworld
With KDE 3
Quite easy:
gcc printtest.cpp -o print -I/usr/lib/qt3/include \ -I/opt/kde3/include -L/opt/kde3/lib \ -L/usr/lib/qt3/lib -lqt-mt -lkdeprint
See also
- Point your konqueror to kde:kprinter