Difference between revisions of "Development/Tutorials/Printing Hello World"

Jump to: navigation, search
m (Text replace - "<code>" to "<syntaxhighlight lang="text">")
m (Text replace - "</code>" to "</syntaxhighlight>")
Line 31: Line 31:
 
     // this makes the print job start
 
     // this makes the print job start
 
}
 
}
</code>
+
</syntaxhighlight>
  
 
== How to compile ==
 
== How to compile ==
Line 42: Line 42:
 
kde4_add_executable(printhelloworld printtest.cpp)
 
kde4_add_executable(printhelloworld printtest.cpp)
 
target_link_libraries(printhelloworld ${${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY})
 
target_link_libraries(printhelloworld ${${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY})
</code>
+
</syntaxhighlight>
  
 
=== Make and Run ===
 
=== Make and Run ===

Revision as of 21:54, 29 June 2011

Contents

The mission

Print Hello World on your printer.

The code

  1. #include <qpainter.h>
  2. #include <qprinter.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.     QPrinter printer;
  20.     printer.setFullPage(true);
  21.     QPainter painter;
  22.     painter.begin(&printer);
  23.     painter.drawText(100,100,"Hello World");
  24.     painter.end(); 
  25.     // this makes the print job start
  26. }

How to compile

CMakeLists.txt

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

Make and Run

Then do:

cmake .
make
./printhelloworld

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