Ticket #427: qt_example.patch
File qt_example.patch, 8.8 KB (added by ujwal, 13 years ago) |
---|
-
CREDITS
901 901 U: ujwalic 902 902 E: ujwalic@gmail.com 903 903 D: OpenGL/GLUT include file order with MSVS 904 D: Updated Qt/NCI example for Windows 904 905 905 906 N: Uri Guttman 906 907 D: Lot of general Parrot design hints -
examples/nci/QtHelloWorld.pasm
11 11 12 12 =head1 DESCRIPTION 13 13 14 Sample "Hello World" with Qt, via Parrot Native Call Interface ( nci). See14 Sample "Hello World" with Qt, via Parrot Native Call Interface (NCI). See 15 15 F<docs/pdds/pdd03_calling_conventions.pod>. 16 16 17 Qt is a multiplatform C++ GUI applicationframework18 (L http://doc.trolltech.com/3.1/aboutqt.html>). You'll need to build19 F<libPQt.so> and install it in F<runtime/parrot/dynext> for this to17 Qt â 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 19 F<libPQt.so> or F<PQt.dll> and install it in F<runtime/parrot/dynext> for this to 20 20 work, see F<examples/nci/PQt.C> for more information. 21 21 22 22 Note that this will either need JIT for building the NCI-functions on … … 35 35 set P2, P5 # remember pApp 36 36 37 37 # get and invoke QLabel_new 38 set S5, "Hello, world!"39 38 dlfunc P0, P1, "QLabel_new", "pt" 40 39 # if you need more labels, save P0 = QLabel_new() function 40 set_args "0", "Hello, world!" 41 get_results "0", P5 41 42 invokecc P0 42 43 set P6, P5 # save pLabel 43 44 44 45 # size the QLabel 45 set I5, 30 # y46 set I6, 120 # x47 46 dlfunc P0, P1, "QLabel_resize", "vpii" 47 set_args "0,0,0", P6, 120, 30 48 48 invokecc P0 49 49 50 # register the label51 dlfunc P0, P1, "QApplication_setMainWidget", "vpp"52 set P5, P6 # pLabel53 set P6, P2 # pApp54 invokecc P055 # P5 = label56 50 dlfunc P0, P1, "QLabel_show", "vp" 57 51 invokecc P0 58 52 59 53 # and go 60 54 dlfunc P0, P1,"QApplication_exec", "vp" 61 set P5, P2 # app55 set_args "0", P2 62 56 invokecc P0 63 57 end 64 58 -
examples/nci/PQt.C
1 /*2 3 # Copyright (C) 2001-2003, Parrot Foundation.4 # $Id$5 6 =head1 NAME7 8 examples/nci/PQt.C - Qt/Parrot Library9 10 =head1 SYNOPSIS11 12 Compile with:13 14 g++ -fPIC -I$QTDIR/include -L$QTDIR -c PQt.C15 16 gcc -shared -o libPQt.so PQt.o $QTDIR/lib/libqt.so17 18 Or something like that...19 20 =head1 DESCRIPTION21 22 Qt Native interface for Parrot. See F<examples/nci/QtHelloWorld.pasm>23 for more information.24 25 =cut26 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 bindings40 41 =over 442 43 =item C<QApplication *QApplication_new(void)>44 45 =cut46 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 =cut62 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 =cut75 76 */77 78 void QApplication_setMainWidget(QApplication *app, QWidget *w)79 {80 app->setMainWidget(w);81 }82 83 /*84 85 =back86 87 =head2 QLabel bindings88 89 =over 490 91 =item C<QLabel * QLabel_new(const char *txt)>92 93 =cut94 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 =cut108 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 =cut121 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 =back134 135 =head1 SEE ALSO136 137 F<examples/nci/QtHelloWorld.pasm>,138 F<docs/pdds/pdd03_calling_conventions.pod>.139 140 =cut141 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 8 examples/nci/PQt.cpp - Qt/Parrot Library 9 10 =head1 SYNOPSIS 11 12 Compile 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 20 Windows: 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 30 Or something like that... 31 32 =head1 DESCRIPTION 33 34 Qt Native interface for Parrot. See F<examples/nci/QtHelloWorld.pir> 35 for 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> 48 extern "C" { 49 50 PQT_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 */ 63 PQT_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 80 PQT_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 99 PQT_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 113 PQT_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 126 PQT_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 139 F<examples/nci/QtHelloWorld.pir>, 140 F<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 6 examples/nci/QtHelloWorld.pir - Qt Example 7 8 =head1 SYNOPSIS 9 10 % ./parrot examples/nci/QtHelloWorld.pir 11 12 =head1 DESCRIPTION 13 14 Sample "Hello World" with Qt, via Parrot Native Call Interface (NCI). See 15 F<docs/pdds/pdd03_calling_conventions.pod>. 16 17 Qt â 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 19 F<libPQt.so> or F<PQt.dll> and install it in F<runtime/parrot/dynext> for this to 20 work, see F<examples/nci/PQt.C> for more information. 21 22 Note that this will either need JIT for building the NCI-functions on 23 the fly. If this is not available try adding missing signatures to 24 F<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 67 F<examples/nci/PQt.C>, F<docs/pdds/pdd03_calling_conventions.pod>. 68 69 =cut