Re: [Qt-jambi-interest] Extending an ItemView

2008-07-07 Thread Eskil Abrahamsen Blomfeldt
[EMAIL PROTECTED] wrote:
 Please, I want to migrate to Qt Jambi for a special project. I need to  
 know how to start from tyhe scratch. First is to install the Qt Jambi  
 in my machine, test it with Hello World! and continue from there.  
 Please, I need your help right now.
   

Hi,

I recommend you start by downloading the Qt Jambi package from our web page:

http://trolltech.com/downloads/opensource#qt-jambi-open-source

and then read the simple installation guide here:


http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-installation.html

Then I recommend you go through the tutorial here:


http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-examples.html#tutorial

That should give you some initial insight into how things work.

Good luck!

-- Eskil
___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest


[Qt-jambi-interest] Jambi and JNI Integration

2008-07-07 Thread Adam Batkin
Hi,

I had posted a while back about wrapping the Poppler PDF library using QT 
Jambi, so that 
it could be used from Java. Although Poppler uses C++ Namespaces, I wrapped the 
3 or 4 
functions that I wanted in my own class, used the Jambi Generator and 
everything was 
great. At the time, it was mentioned that better Namespace support was coming 
with 4.4 so 
I figured I would wait until then to properly wrap the entire library 
(without having to 
also write my own C++ classes to wrap ever Poppler class that I wanted).

Anyway, I've now set out to write my own JNI code to do what I want, instead of 
using the 
Jambi Generator. Everything was working nicely until trying to transfer a 
QImage from C++ 
to a Java/Jambi QImage. Back in February, Gunnar suggested stealing some logic 
from the 
generated Jambi code, in particular QPixmap::toImage():
 jobject jimg =
 qtjambi_from_object(env,
 image,
 QImage,
 com/trolltech/qt/gui/,
 true);

This works -- almost. I get back a valid Java QImage object 
(System.err.println(image) 
prints something like [EMAIL PROTECTED]) but when I try to do anything 
with it (like call image.width()), the JVM crashes.

Now, the image object (QImage) that I'm getting back is on the stack (hence the 
address-of 
). If I make a copy of it on the heap (QImage *copy = new QImage(image)) and 
then pass 
that copy pointer directly to the qtjambi_from_object function (i.e. no 
address-of 
operator  since it is naturally a pointer) then it doesn't crash -- so long as 
I don't 
delete the copy pointer (which makes that a big memory leak). (creating a copy, 
not 
deleting it, but using the original image in qtjambi_from_object DOES crash 
the JVM (weird)).

Something else that is weird (though this may be a red-herring, i.e. luck) if I 
construct 
more than 1 QImage (in Java, i.e. QImage i1 = page.renderToImage(); QImage i2 = 
page.renderToImage();) calling i1.width() crashes the JVM but i2.width() does 
not! (i1 
being the first QImage created this way) In fact, just the line new 
QPixmap().toImage() 
seems to prevent a crash. Through some trial and error, I tried inlining a 
bunch of the 
code from qtjambi_from_object and it seems that just calling the following one 
line before 
calling qtjambi_from_object prevents a crash:
resolveClass(env, className, packageName);

Thoughts?

Thanks,

-Adam Batkin

___
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest