Initializing my QApplication first does in fact solve the problem. I'm not sure 
how I 
missed that (*smacks forehead*). Mostly because I was doing this in a 4-line 
test harness 
and not an actual program (which would of course have initialized QT since 
using QT Jambi 
is the whole point of this exercise!)

You mentioned being able to move some code around to fix this particular issue 
but that 
wouldn't be a general fix; I would say that even better (if possible) would be 
to warn 
that you have to initialize QT first. I mention this because some classes do in 
fact print 
warnings if you try to use them without initializing QT first (for example when 
I was 
testing and I created an empty QPixmap, it yelled at me). In other words, what 
I did was 
wrong, but it would have been helpful to get a warning or something (since JVM 
crashes 
aren't the easiest things to debug)

Anyway, thanks for the help!

-Adam Batkin

Eskil Abrahamsen Blomfeldt wrote:
> Adam Batkin wrote:
>> 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.
>>   
> 
> Hi, Adam.
> 
> Has Qt Jambi been properly initialized at this point? I.e. you need to 
> initialize each of the libraries you use before they can be used, 
> otherwise Qt Jambi won't know e.g. that it has to copy the QImage into a 
> new object before linking it into a Java object, and you will get a Java 
> object with a pointer into the stack. The initialization of Qt Jambi 
> libraries is done the first time a class from the library is loaded by 
> the virtual machine. In your case, I think you are calling the 
> conversion code before loading any Jambi GUI classes. The conversion 
> code itself will resolve and load the QImage class, thus initializing 
> the GUI library, but unfortunately this is too late for the first 
> conversion, and the first Java object you retrieve will contain a 
> pointer to the object you allocated on stack. This is why you can fix 
> the problem by manually loading the class using the resolveClass() call, 
> or by calling another method which causes the library to be initialized.
> 
> We can easily fix this particular problem by moving some code around, 
> and I'll make a suggestion to do so. However, I'm not convinced that 
> we'll be able to fix all related issues, so I recommend you initialize 
> the library prior to using Qt Jambi. For instance, we don't support 
> having Qt Jambi application that have not called 
> QApplication.initialize() or QCoreApplication.initialize() (the former 
> in your case.) If you call QApplication.initialize() in the beginning of 
> your application, this should cause the GUI library to be initialized.
> 
> -- Eskil
> 
> 

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

Reply via email to