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

Jump to: navigation, search
 
(6 intermediate revisions by 2 users not shown)
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.}}
  
=The mission=
+
=Цель=
Print '''Hello World''' on your printer.
+
Печать '''Hello World''' на принтере.
  
=The KDE version=
+
=Версия KDE=
This code will work for KDE 3 as for KDE 4.
+
Этот код будет работать как для KDE 3 так и для KDE 4.
  
=The code=
+
=Код=
<code cppqt n>
+
<syntaxhighlight lang="cpp-qt" line>
 
#include <kprinter.h>
 
#include <kprinter.h>
 
#include <qpainter.h>
 
#include <qpainter.h>
Line 40: Line 40:
 
   }
 
   }
 
}
 
}
</code>
+
</syntaxhighlight>
  
=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.
+
Пример печати в KDE необходим, как пример собственной конфигурации, включающей конфигурацию принтера. Создадим его как пример класса KApplication.
  
=How to compile=
+
=Как компилировать=
==With KDE 4 and 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} )
 
kde4_add_executable(printhelloworld printtest.cpp)
 
kde4_add_executable(printhelloworld printtest.cpp)
 
target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})
 
target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})
</code>
+
</syntaxhighlight>
===Make and Run===
+
===Выполнение сборки и запуск (Make and Run)===
Then do:
+
Затем делаем:
 
  cmake .
 
  cmake .
 
  make
 
  make
 
  ./printhelloworld
 
  ./printhelloworld
  
==With KDE 3==
+
==С KDE 3==
Quite easy:
+
Лёгкий способ:
 
  gcc printtest.cpp -o print -I/usr/lib/qt3/include \
 
  gcc printtest.cpp -o print -I/usr/lib/qt3/include \
 
  -I/opt/kde3/include -L/opt/kde3/lib \
 
  -I/opt/kde3/include -L/opt/kde3/lib \
 
  -L/usr/lib/qt3/lib  -lqt-mt -lkdeprint
 
  -L/usr/lib/qt3/lib  -lqt-mt -lkdeprint
  
=See also=
+
=Смотрите также=
 
* Point your konqueror to [http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeprint/html/classKPrinter.html kde:kprinter]
 
* Point your konqueror to [http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeprint/html/classKPrinter.html kde:kprinter]
 
[[Category:KDE4]]
 
[[Category:KDE4]]
 
[[Category:C++]]
 
[[Category:C++]]

Latest revision as of 13:03, 18 July 2012


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

Contents

[edit] Цель

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

[edit] Версия KDE

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

[edit] Код

  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. }

[edit] Разъяснение

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

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

[edit] С KDE 4 и CMake

[edit] CMakeLists.txt

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

[edit] Выполнение сборки и запуск (Make and Run)

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

cmake .
make
./printhelloworld

[edit] С 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

[edit] Смотрите также


This page was last modified on 18 July 2012, at 13:03. This page has been accessed 2,679 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal