cvsuser     03/10/11 21:44:05

  Added:       examples/pni PQt.C QtHelloWorld.pasm
  Log:
  pxs is now pni, remove old references and directory
  
  Revision  Changes    Path
  1.1                  parrot/examples/pni/PQt.C
  
  Index: PQt.C
  ===================================================================
  /*
   * Qt Native interface for Parrot - Sample for playing with the
   * extension design.
   *
   * compile with:  g++ -fPIC -I$QTDIR/include -L$QTDIR -c PQt.C
   *                gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libqt.so
   *
   * Or something like that...
   */
  
  
  #include <qapplication.h>
  #include <qlabel.h>
  extern "C" {
  #include <stdio.h>
  #include <dlfcn.h>
  
  QApplication * pApp;
  
  
  /*
   * QApplication bindings
   */
  QApplication *QApplication_new(void) {
      int PQtargc = 0;
      char *PQtargv[2];
      PQtargv[0] = "";
      PQtargv[1] = NULL;
      pApp = new QApplication(PQtargc, PQtargv);
      return pApp;
  }
  
  void QApplication_exec(QApplication *app)
  {
      app->exec();
  }
  
  void QApplication_setMainWidget(QApplication *app, QWidget *w)
  {
      app->setMainWidget(w);
  }
  
  
  /*
   * QLabel bindings
   */
  
  QLabel * QLabel_new(const char *txt)
  {
      QLabel * pLabel = new QLabel(txt, 0);
      return pLabel;
  }
  
  void QLabel_show(QLabel *label)
  {
      label->show();
  }
  
  void QLabel_resize(QLabel *label, int x, int y)
  {
      label->resize(x, y);
  }
  
  
  
  }
  
  
  
  
  1.1                  parrot/examples/pni/QtHelloWorld.pasm
  
  Index: QtHelloWorld.pasm
  ===================================================================
  # Sample "Hello World" with Qt, via Parrot Native Call API (nci)
  # s. docs/pdds/pdd03_calling_conventions.pod
  #
  # You'll need to build libPQt.so for this to work, see
  # pqt.C for more info.
  # Please note: this will either need JIT/i386 for building the
  #              nci-functions on the fly, or adding missing
  #              signatures to call_list.txt and rebuilding parrot/imcc
  #
  # make && make -s -C languages/imcc
  # ln -s languages/imcc imcc
  # cd examples/pni
  # export LD_LIBRARY_PATH=.
  # ../../imcc QtHelloWorld.pasm
  
  
  # load the shared lib
      loadlib P1, "libPQt.so"
      print "Loaded\n"
  
  # get and invoke the QApplication_new function
      dlfunc P0, P1, "QApplication_new", "pv"
      invoke
      set P2, P5        # remember pApp
  
  # get and invoke QLabel_new
      set S5, "Hello, world!"
      dlfunc P0, P1, "QLabel_new", "pt"
      # if you need more labels, save P0 = QLabel_new() function
      invoke
      set P6, P5        # save pLabel
  
  # size the QLabel
      set I5, 30        # y
      set I6, 120       # x
      dlfunc P0, P1, "QLabel_resize", "vpii"
      invoke
  
  # register the label
      dlfunc P0, P1, "QApplication_setMainWidget", "vpp"
      set P5, P6        # pLabel
      set P6, P2        # pApp
      invoke
      # P5  = label
      dlfunc P0, P1, "QLabel_show", "vp"
      invoke
  
  # and go
      dlfunc P0, P1,"QApplication_exec", "vp"
      set P5, P2        # app
      invoke
      end
  
  
  

Reply via email to