Difference between revisions of "Development/Tutorials/Printing Hello World (ru)"

Jump to: navigation, search
m (Text replace - "<code cppqt n>" to "<syntaxhighlight lang="cpp-qt" line>")
m (Text replace - "<code>" to "<syntaxhighlight lang="text">")
Line 48: Line 48:
 
==С KDE 4 и CMake==
 
==С KDE 4 и CMake==
 
===CMakeLists.txt===
 
===CMakeLists.txt===
<code>
+
<syntaxhighlight lang="text">
 
find_package(KDE4 REQUIRED)
 
find_package(KDE4 REQUIRED)
 
include_directories( ${KDE4_INCLUDES} )
 
include_directories( ${KDE4_INCLUDES} )

Revision as of 21:45, 29 June 2011


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>
  7.  
  8. /*
  9. This prints Hello World on your printer
  10. */
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.   KAboutData aboutData( "test", "test", "1.0", "test",
  15.       KAboutData::License_GPL, "(c) 2006" );
  16.   KCmdLineArgs::init( argc, argv, &aboutData );
  17.   KApplication app;
  18.  
  19.   KPrinter job;
  20.   job.setFullPage( true );
  21.   if ( job.setup() )
  22.   {
  23.     QPainter painter;
  24.     painter.begin( &job );
  25.     painter.drawText(100,100,"Hello World");
  26.     painter.end(); 
  27.     // this makes the print job start
  28.   }
  29. }
  30. </code>
  31.  
  32. =Разъяснение=
  33. Пример печати в KDE необходим, как пример собственной конфигурации, включающей конфигурацию принтера. Создадим его как пример класса KApplication.
  34.  
  35. =Как компилировать=
  36. ==С KDE 4 и CMake==
  37. ===CMakeLists.txt===
  38. <syntaxhighlight lang="text">
  39. find_package(KDE4 REQUIRED)
  40. include_directories( ${KDE4_INCLUDES} )
  41. kde4_add_executable(printhelloworld printtest.cpp)
  42. target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})
  43. </code>
  44. ===Выполнение сборки и запуск (Make and Run)===
  45. Затем делаем:
  46.  cmake .
  47.  make
  48.  ./printhelloworld
  49.  
  50. ==С KDE 3==
  51. Лёгкий способ:
  52.  gcc printtest.cpp -o print -I/usr/lib/qt3/include \
  53.  -I/opt/kde3/include -L/opt/kde3/lib \
  54.  -L/usr/lib/qt3/lib  -lqt-mt -lkdeprint
  55.  
  56. =Смотрите также=
  57. * Point your konqueror to [http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeprint/html/classKPrinter.html kde:kprinter]
  58. [[Category:KDE4]]
  59. [[Category:C++]]

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