(→With KDE 4: Add CMakeLists.txt for KDE4 (now less complicated :) )) |
(→How to compile: Get rid of gcc command for KDE4. Use CMake instead.) |
||
| Line 43: | Line 43: | ||
=How to compile= | =How to compile= | ||
| − | ==With KDE 4 | + | ==With KDE 4 and CMake== |
| − | + | ===CMakeLists.txt=== | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
<code> | <code> | ||
| − | |||
find_package(KDE4 REQUIRED) | find_package(KDE4 REQUIRED) | ||
include_directories( ${KDE4_INCLUDES} ) | include_directories( ${KDE4_INCLUDES} ) | ||
| − | kde4_add_executable(printhelloworld | + | kde4_add_executable(printhelloworld printtest.cpp) |
target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS}) | target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS}) | ||
</code> | </code> | ||
| − | + | ===Make and Run=== | |
Then do: | Then do: | ||
cmake . | cmake . | ||
| Line 68: | Line 59: | ||
==With KDE 3== | ==With KDE 3== | ||
Quite easy: | Quite easy: | ||
| − | gcc printtest.cpp -o print -I/usr/lib/qt3/include -I/opt/kde3/include | + | 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= | =See also= | ||
Contents |
Print Hello World on your printer.
This code will work for KDE 3 as for KDE 4.
/* 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 khello;
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
}
}
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.
find_package(KDE4 REQUIRED)
include_directories( ${KDE4_INCLUDES} )
kde4_add_executable(printhelloworld printtest.cpp)
target_link_libraries(printhelloworld ${KDE4_KDEPRINT_LIBS})
Then do:
cmake . make ./printhelloworld
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
| Tip |
|---|
| Note: This page deals with content related to KDE 3. If you are developing for KDE 4, this information might not be valid anymore. |
| Tip |
|---|
| Note: This page is about KDE 4. It isn't applicable for KDE 3 development. |