Re: [Kde-bindings] [PATCH] kdebindings: add perl string marshaller for QByteArray
Gary Greene <[email protected]> Thu, 12 Oct 2006 11:46:47 -0400
| Newsgroups | gmane.comp.kde.devel.perl |
|---|---|
| Organization | Shore Line Technologies, LLC. |
| Message-ID | <[email protected]> |
--===============2075578812== Content-Type: multipart/signed; boundary="nextPart1964908.HzJSmoEQo4"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1964908.HzJSmoEQo4 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 12 October 2006 04:32 am, Richard Dale wrote: > Hi Gary > > On Wednesday 11 October 2006 20:53, Gary Greene wrote: > > On Monday 09 October 2006 05:40 am, Richard Dale wrote: > > > On Monday 09 October 2006 05:27, Logan Rathbone wrote: > > > > I was always using PerlQt's version of smoke, and I had written a > > > > couple programs using it. The other day though, I decided to try to > > > > build it against kdebindings's smoke. However, some of my code bro= ke > > > > because I was using some Qt functions that take QByteArrays, and for > > > > some reason kdebindings's smoke doesn't allow for that and PerlQt's > > > > does. So this patch seems to add that marshaller into kdebindings's > > > > smoke, and hence unbreaks my code when built against it. > > > > > > The problem is that if you have automatic Perl <--> C++ QByteArray > > > conversion it makes it difficult to use QTextOStreams for instance. > > > When you write to the stream, the underlying QByteArray will be > > > updated, but possibly not the original string you passed. So I found > > > the automatic conversion was more trouble than it's worth. I think a > > > better solution to get the current Smoke lib working with PerlQt is to > > > remove the QByteArray marshalling from handlers.cpp. I'll forward this > > > mail to the kde-bindings and perlqt mailing lists to see what Ashley > > > Winters thinks anyway. > > > > > > -- Richard > > > _______________________________________________ > > > Kde-perl mailing list > > > [email protected] > > > https://mail.kde.org/mailman/listinfo/kde-perl > > > > Richard, the only problem with this is that it completely breaks usage = of > > QByteArrays for PerlQt. Logan has some apps in PhoeNUX OS that actually > > use QByteArray constructs, thus the reason WHY he patched our build of > > kdebindings to get it working and submitted the patch to kde-devel. The > > definitive plan for PheoNUX is to have the Perl Qt3 / KDE bindings > > solidly working for all apps that we are developing, and then port the > > codebase of PerlQt/PerlKDE to Qt4 / KDE 4 so we get a sane path for when > > KDE 4 is out. This measn that short-changing the binding in this case > > isn't a good option unless we can get QByteArrays working with the > > marshaller. > > You can still use Qt::ByteArrays and they are marshalled find, but you mu= st > create them with Qt::ByteArray.new in Ruby, and the equivalent in PerlQt. > > Here is an example of why you need the QByteArray class in the Smoke > library as an ordinary class, from Qt4 QtRuby in > qtruby/rubylib/examples/network/fortuneserver/server.rb: > > def sendFortune > block =3D Qt::ByteArray.new > outf =3D Qt::DataStream.new(block, Qt::IODevice::WriteOnly) > outf.version =3D Qt::DataStream::Qt_4_0 > outf << 0 # Write a 4 byte integer > outf << @fortunes[rand(@fortunes.length)] > outf.device.seek(0) > outf << (block.length - 4) # 4 bytes is the size of an integer > > clientConnection =3D @tcpServer.nextPendingConnection() > connect(clientConnection, SIGNAL('disconnected()'), > clientConnection, SLOT('deleteLater()')) > > clientConnection.write(block) > clientConnection.disconnectFromHost > end > > You open a stream on 'block', write a few things to it, and then later wh= en > you use 'block' it needs to have been updated. In Ruby, when 'block' was a > Ruby string and marshalled to a QByteArray before being passed to the > Qt::DataStream constructor, it meant that the Ruby String never got > updated. In some other languages like C# the problem is even worse becau= se > Strings are immutable, and you would have to use a StringBuffer instance > instead, and manage to keep it updated in line with the underlying > QByteArray. Perhaps in Perl you can manage to make it work in the case, I > don't know. > > Here is how it used to look in QtRuby, and it didn't work: > > def sendFortune > # Create block as a Ruby String > block =3D "" > > # 'block' is marshalled to a C++ QByteArray here: > outf =3D Qt::DataStream.new(block, Qt::IODevice::WriteOnly) > > outf.version =3D Qt::DataStream::Qt_4_0 > outf << 0 # Write a 4 byte integer > outf << @fortunes[rand(@fortunes.length)] > outf.device.seek(0) > outf << (block.length - 4) # 4 bytes is the size of an integer > > clientConnection =3D @tcpServer.nextPendingConnection() > connect(clientConnection, SIGNAL('disconnected()'), > clientConnection, SLOT('deleteLater()')) > > # How is block updated here to reflect the current value of the > # QByteArray that was passed to the QDataStream constructor > # above? > clientConnection.write(block) > clientConnection.disconnectFromHost > end > > Assuming you're porting PertQt code from Qt3 to Qt4, I think this is a > minor conversion issue, and I would have thought it shouldn't be too > difficult to amend the code. > > -- Richard > _______________________________________________ > Kde-perl mailing list > [email protected] > https://mail.kde.org/mailman/listinfo/kde-perl So then this means that it becomes an explicit declaration? This seems to f= ly=20 in the face of Perl's implicitness everywhere but, I think I can live with= =20 that now that that's been explained. Important note though, we're not at th= e=20 stage of porting code yet, as the Perl Qt4 binding is still in=20 pre-development stages at this time as I'm still looking for paying work so= I=20 can get out of my Parents and get on broadband instead of this nasty dial-u= p=20 they've got. --nextPart1964908.HzJSmoEQo4 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.9.20 (GNU/Linux) iD8DBQBFLmNr+psNrGG9CbMRAq9mAKDUmkIHc2HAUM2e0lainerIV2OBIACfZzLI DgduANoUzAt+xMIhWKYeFNA= =vOK/ -----END PGP SIGNATURE----- --nextPart1964908.HzJSmoEQo4-- --===============2075578812== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kde-perl mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-perl --===============2075578812==--