Ticket #427: qt_example.patch

File qt_example.patch, 8.8 KB (added by ujwal, 13 years ago)

[PATCH] for Qt/NCI Example

  • CREDITS

     
    901901U: ujwalic 
    902902E: ujwalic@gmail.com 
    903903D: OpenGL/GLUT include file order with MSVS 
     904D: Updated Qt/NCI example for Windows 
    904905 
    905906N: Uri Guttman 
    906907D: Lot of general Parrot design hints 
  • examples/nci/QtHelloWorld.pasm

     
    1111 
    1212=head1 DESCRIPTION 
    1313 
    14 Sample "Hello World" with Qt, via Parrot Native Call Interface (nci). See 
     14Sample "Hello World" with Qt, via Parrot Native Call Interface (NCI). See 
    1515F<docs/pdds/pdd03_calling_conventions.pod>. 
    1616 
    17 Qt is a multiplatform C++ GUI application framework 
    18 (Lhttp://doc.trolltech.com/3.1/aboutqt.html>). You'll need to build 
    19 F<libPQt.so> and install it in F<runtime/parrot/dynext> for this to 
     17Qt – A cross-platform application and UI framework 
     18(L<http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt>). You'll need to build 
     19F<libPQt.so> or F<PQt.dll> and install it in F<runtime/parrot/dynext> for this to 
    2020work, see F<examples/nci/PQt.C> for more information. 
    2121 
    2222Note that this will either need JIT for building the NCI-functions on 
     
    3535    set P2, P5  # remember pApp 
    3636 
    3737# get and invoke QLabel_new 
    38     set S5, "Hello, world!" 
    3938    dlfunc P0, P1, "QLabel_new", "pt" 
    4039    # if you need more labels, save P0 = QLabel_new() function 
     40    set_args "0", "Hello, world!" 
     41    get_results "0", P5 
    4142    invokecc P0 
    4243    set P6, P5  # save pLabel 
    4344 
    4445# size the QLabel 
    45     set I5, 30  # y 
    46     set I6, 120 # x 
    4746    dlfunc P0, P1, "QLabel_resize", "vpii" 
     47    set_args "0,0,0", P6, 120, 30 
    4848    invokecc P0 
    4949 
    50 # register the label 
    51     dlfunc P0, P1, "QApplication_setMainWidget", "vpp" 
    52     set P5, P6  # pLabel 
    53     set P6, P2  # pApp 
    54     invokecc P0 
    55     # P5  = label 
    5650    dlfunc P0, P1, "QLabel_show", "vp" 
    5751    invokecc P0 
    5852 
    5953# and go 
    6054    dlfunc P0, P1,"QApplication_exec", "vp" 
    61     set P5, P2  # app 
     55    set_args "0", P2 
    6256    invokecc P0 
    6357    end 
    6458 
  • examples/nci/PQt.C

     
    1 /* 
    2  
    3 # Copyright (C) 2001-2003, Parrot Foundation. 
    4 # $Id$ 
    5  
    6 =head1 NAME 
    7  
    8 examples/nci/PQt.C - Qt/Parrot Library 
    9  
    10 =head1 SYNOPSIS 
    11  
    12 Compile with: 
    13  
    14     g++ -fPIC -I$QTDIR/include -L$QTDIR -c PQt.C 
    15  
    16     gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libqt.so 
    17  
    18 Or something like that... 
    19  
    20 =head1 DESCRIPTION 
    21  
    22 Qt Native interface for Parrot. See F<examples/nci/QtHelloWorld.pasm> 
    23 for more information. 
    24  
    25 =cut 
    26  
    27 */ 
    28  
    29 #include <qapplication.h> 
    30 #include <qlabel.h> 
    31 extern "C" { 
    32 #include <stdio.h> 
    33 #include <dlfcn.h> 
    34  
    35 QApplication * pApp; 
    36  
    37 /* 
    38  
    39 =head2 QApplication bindings 
    40  
    41 =over 4 
    42  
    43 =item C<QApplication *QApplication_new(void)> 
    44  
    45 =cut 
    46  
    47 */ 
    48 QApplication *QApplication_new(void) { 
    49     int PQtargc = 0; 
    50     char *PQtargv[2]; 
    51     PQtargv[0] = ""; 
    52     PQtargv[1] = NULL; 
    53     pApp = new QApplication(PQtargc, PQtargv); 
    54     return pApp; 
    55 } 
    56  
    57 /* 
    58  
    59 =item C<void QApplication_exec(QApplication *app)> 
    60  
    61 =cut 
    62  
    63 */ 
    64  
    65 void QApplication_exec(QApplication *app) 
    66 { 
    67     app->exec(); 
    68 } 
    69  
    70 /* 
    71  
    72 =item C<void QApplication_setMainWidget(QApplication *app, QWidget *w)> 
    73  
    74 =cut 
    75  
    76 */ 
    77  
    78 void QApplication_setMainWidget(QApplication *app, QWidget *w) 
    79 { 
    80     app->setMainWidget(w); 
    81 } 
    82  
    83 /* 
    84  
    85 =back 
    86  
    87 =head2 QLabel bindings 
    88  
    89 =over 4 
    90  
    91 =item C<QLabel * QLabel_new(const char *txt)> 
    92  
    93 =cut 
    94  
    95 */ 
    96  
    97 QLabel * QLabel_new(const char *txt) 
    98 { 
    99     QLabel * pLabel = new QLabel(txt, 0); 
    100     return pLabel; 
    101 } 
    102  
    103 /* 
    104  
    105 =item C<void QLabel_show(QLabel *label)> 
    106  
    107 =cut 
    108  
    109 */ 
    110  
    111 void QLabel_show(QLabel *label) 
    112 { 
    113     label->show(); 
    114 } 
    115  
    116 /* 
    117  
    118 =item C<void QLabel_resize(QLabel *label, int x, int y)> 
    119  
    120 =cut 
    121  
    122 */ 
    123  
    124 void QLabel_resize(QLabel *label, int x, int y) 
    125 { 
    126     label->resize(x, y); 
    127 } 
    128  
    129 } 
    130  
    131 /* 
    132  
    133 =back 
    134  
    135 =head1 SEE ALSO 
    136  
    137 F<examples/nci/QtHelloWorld.pasm>, 
    138 F<docs/pdds/pdd03_calling_conventions.pod>. 
    139  
    140 =cut 
    141  
    142 */ 
    143  
    144 /* 
    145  * Local variables: 
    146  *   c-file-style: "parrot" 
    147  * End: 
    148  * vim: expandtab shiftwidth=4: 
    149  */ 
  • examples/nci/PQt.cpp

     
     1/* 
     2 
     3# Copyright (C) 2001-2003, Parrot Foundation. 
     4# $Id: PQt.C 37201 2009-03-08 12:07:48Z fperrad $ 
     5 
     6=head1 NAME 
     7 
     8examples/nci/PQt.cpp - Qt/Parrot Library 
     9 
     10=head1 SYNOPSIS 
     11 
     12Compile with: 
     13 
     14*NIX: 
     15 
     16    $ g++ -fPIC -I$QTDIR/include -L$QTDIR -c PQt.cpp 
     17 
     18    $ gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libqt.so 
     19 
     20Windows: 
     21 
     22    > "%VS90COMNTOOLS%\vsvars32.bat" 
     23 
     24    > set INCLUDE=%QTDIR%\include;%QTDIR%\include\QtGui;%INCLUDE% 
     25     
     26    > set LIB=%QTDIR%\lib;%LIB% 
     27 
     28    > cl /LD PQt.cpp QtGui4.lib QtCore4.lib 
     29 
     30Or something like that... 
     31 
     32=head1 DESCRIPTION 
     33 
     34Qt Native interface for Parrot. See F<examples/nci/QtHelloWorld.pir> 
     35for more information. 
     36 
     37=cut 
     38 
     39*/ 
     40 
     41#ifdef _WIN32 
     42  #define PQT_API __declspec(dllexport) 
     43#else 
     44  #define PQT_API  
     45#endif 
     46 
     47#include <QtGui> 
     48extern "C" { 
     49 
     50PQT_API QApplication * pApp; 
     51 
     52/* 
     53 
     54=head2 QApplication bindings 
     55 
     56=over 4 
     57 
     58=item C<QApplication *QApplication_new(void)> 
     59 
     60=cut 
     61 
     62*/ 
     63PQT_API QApplication *QApplication_new(void) { 
     64    int PQtargc = 0; 
     65    char *PQtargv[2]; 
     66    PQtargv[0] = ""; 
     67    PQtargv[1] = NULL; 
     68    pApp = new QApplication(PQtargc, PQtargv); 
     69    return pApp; 
     70} 
     71 
     72/* 
     73 
     74=item C<void QApplication_exec(QApplication *app)> 
     75 
     76=cut 
     77 
     78*/ 
     79 
     80PQT_API void QApplication_exec(QApplication *app) 
     81{ 
     82    app->exec(); 
     83} 
     84 
     85/* 
     86 
     87=back 
     88 
     89=head2 QLabel bindings 
     90 
     91=over 4 
     92 
     93=item C<QLabel * QLabel_new(const char *txt)> 
     94 
     95=cut 
     96 
     97*/ 
     98 
     99PQT_API QLabel * QLabel_new(const char *txt) 
     100{ 
     101    QLabel * pLabel = new QLabel(txt, 0); 
     102    return pLabel; 
     103} 
     104 
     105/* 
     106 
     107=item C<void QLabel_show(QLabel *label)> 
     108 
     109=cut 
     110 
     111*/ 
     112 
     113PQT_API void QLabel_show(QLabel *label) 
     114{ 
     115    label->show(); 
     116} 
     117 
     118/* 
     119 
     120=item C<void QLabel_resize(QLabel *label, int x, int y)> 
     121 
     122=cut 
     123 
     124*/ 
     125 
     126PQT_API void QLabel_resize(QLabel *label, int x, int y) 
     127{ 
     128    label->resize(x, y); 
     129} 
     130 
     131} 
     132 
     133/* 
     134 
     135=back 
     136 
     137=head1 SEE ALSO 
     138 
     139F<examples/nci/QtHelloWorld.pir>, 
     140F<docs/pdds/pdd03_calling_conventions.pod>. 
     141 
     142=cut 
     143 
     144*/ 
     145 
     146/* 
     147 * Local variables: 
     148 *   c-file-style: "parrot" 
     149 * End: 
     150 * vim: expandtab shiftwidth=4: 
     151 */ 
  • examples/nci/QtHelloWorld.pir

     
     1# Copyright (C) 2001-2003, Parrot Foundation. 
     2# $Id: QtHelloWorld.pasm 37201 2009-03-08 12:07:48Z fperrad $ 
     3 
     4=head1 NAME 
     5 
     6examples/nci/QtHelloWorld.pir - Qt Example 
     7 
     8=head1 SYNOPSIS 
     9 
     10    % ./parrot examples/nci/QtHelloWorld.pir 
     11 
     12=head1 DESCRIPTION 
     13 
     14Sample "Hello World" with Qt, via Parrot Native Call Interface (NCI). See 
     15F<docs/pdds/pdd03_calling_conventions.pod>. 
     16 
     17Qt – A cross-platform application and UI framework 
     18(L<http://www.qtsoftware.com/about/news/lgpl-license-option-added-to-qt>). You'll need to build 
     19F<libPQt.so> or F<PQt.dll> and install it in F<runtime/parrot/dynext> for this to 
     20work, see F<examples/nci/PQt.C> for more information. 
     21 
     22Note that this will either need JIT for building the NCI-functions on 
     23the fly. If this is not available try adding missing signatures to 
     24F<src/call_list.txt> and rebuilding Parrot. 
     25 
     26=cut 
     27.sub main 
     28     
     29    .local pmc libpqt 
     30    loadlib libpqt, "libPQt" 
     31    if libpqt goto loaded 
     32 
     33  failed: 
     34    .local string message 
     35    message  = 'Install PQt.dll or libPQt.so into runtime/parrot/dynext' 
     36    die message 
     37 
     38  loaded: 
     39    print "Loaded\n" 
     40 
     41    .local pmc QApplication_new, pApp 
     42    dlfunc QApplication_new, libpqt, "QApplication_new", "pv" 
     43    pApp = QApplication_new() 
     44 
     45    .local pmc QLabel_new, pLabel 
     46    .local string caption 
     47    caption = "Hello, world!" 
     48    dlfunc QLabel_new, libpqt, "QLabel_new", "pt" 
     49    pLabel = QLabel_new(caption) 
     50 
     51    .local pmc QLabel_resize 
     52    dlfunc QLabel_resize, libpqt, "QLabel_resize", "vpii" 
     53    QLabel_resize(pLabel, 120, 30) 
     54 
     55    .local pmc QLabel_show 
     56    dlfunc QLabel_show, libpqt, "QLabel_show", "vp" 
     57    QLabel_show(pLabel) 
     58 
     59    .local pmc QApplication_exec 
     60    dlfunc QApplication_exec, libpqt,"QApplication_exec", "vp" 
     61    QApplication_exec(pApp) 
     62 
     63.end 
     64 
     65=head1 SEE ALSO 
     66 
     67F<examples/nci/PQt.C>, F<docs/pdds/pdd03_calling_conventions.pod>. 
     68 
     69=cut