Development/Tutorials/Printing Hello World (ru)

< Development‎ | Tutorials
Revision as of 11:43, 22 February 2009 by Midnighter (Talk | contribs)

Jump to: navigation, search


Contents

Development/Tutorials/Printing_Hello_World


noframe
 
Note
This tutorial seems not to be up to date with current KDE4 development.

Цель

Печать Hello World на принтере.

Версия KDE

Этот код будет работать как для KDE 3 так и для KDE 4.

Код

  1. include <kprinter.h>
  2. include <qpainter.h>
  3. include <kapplication.h>
  4. include <kaboutdata.h>
  5. include <kmessagebox.h>
  6. 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
 }

}

Разъяснение

Пример печати в KDE необходим, как пример собственной конфигурации, включающей конфигурацию принтера. Создадим его как пример класса KApplication.

Как компилировать

С KDE 4 и CMake

CMakeLists.txt

find_package(KDE4 REQUIRED) include_directories( ${KDE4_INCLUDES} ) kde4_add_executable(printhelloworld printtest.cpp) target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})

Компоновка и запуск

Затем делаем:

cmake .
make
./printhelloworld

С KDE 3

Лёгкий способ:

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

Смотрите так же


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal