Development/Tutorials/Printing Hello World (ru): Difference between revisions
< Development | Tutorials
Midnighter (talk | contribs) No edit summary |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{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.}} | ||
Line 10: | Line 10: | ||
=Код= | =Код= | ||
< | <syntaxhighlight lang="cpp-qt" line> | ||
#include <kprinter.h> | #include <kprinter.h> | ||
#include <qpainter.h> | #include <qpainter.h> | ||
Line 40: | Line 40: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
= | =Разъяснение= | ||
Пример печати в KDE необходим, как пример собственной конфигурации, включающей конфигурацию принтера. Создадим его как пример класса KApplication. | |||
=Как компилировать= | =Как компилировать= | ||
==С KDE 4 и CMake== | ==С KDE 4 и CMake== | ||
===CMakeLists.txt=== | ===CMakeLists.txt=== | ||
< | <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}) | ||
</ | </syntaxhighlight> | ||
===Make and Run=== | ===Выполнение сборки и запуск (Make and Run)=== | ||
Затем делаем: | |||
cmake . | cmake . | ||
make | make | ||
Line 61: | Line 61: | ||
==С KDE 3== | ==С KDE 3== | ||
Лёгкий способ: | |||
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 | ||
=Смотрите | =Смотрите также= | ||
* 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 12:03, 18 July 2012
Note
This tutorial seems not to be up to date with current KDE4 development.
Цель
Печать Hello World на принтере.
Версия KDE
Этот код будет работать как для KDE 3 так и для KDE 4.
Код
#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
}
}
Разъяснение
Пример печати в 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})
Выполнение сборки и запуск (Make and Run)
Затем делаем:
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
Смотрите также
- Point your konqueror to kde:kprinter