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

m (Text replace - "<code cppqt n>" to "<syntaxhighlight lang="cpp-qt" line>")
Line 4: Line 4:
== The code ==
== The code ==
<code cppqt n>
<syntaxhighlight lang="cpp-qt" line>
#include <qpainter.h>
#include <qpainter.h>
#include <qprinter.h>
#include <qprinter.h>

Revision as of 20:32, 29 June 2011

The mission

Print Hello World on your printer.

The code

<syntaxhighlight lang="cpp-qt" line>

  1. include <qpainter.h>
  2. include <qprinter.h>
  3. include <kapplication.h>
  4. include <kaboutdata.h>
  5. include <kmessagebox.h>
  6. 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;
   QPrinter printer;
   QPainter painter;
   painter.drawText(100,100,"Hello World");
   // this makes the print job start


How to compile


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 .

Content is available under Creative Commons License SA 4.0 unless otherwise noted.