[Kde-java] GCJ and qtjava/kdejava

Richard Dale Richard_Dale@tipitina.demon.co.uk
Tue Apr 2 01:44:00 GMT 2002


Hi Bryce

On Tuesday 02 April 2002 2:01 am, Bryce McKinlay wrote:
> Richard Dale wrote:
> >Thanks for the responses to my problem - I've joined the java@gcc.gnu.org
> > list now.
> >
> >I've downloaded and built a gcc-20020325 snapshot, and it has the same bug
> > :-(. The only difference was that gcc 3.1 trashed the stack when it
> > crashed.
>
> Hi Richard,
>
> I gave your test program a try here and it works fine for me with the
> current GCJ 3.1, however I am using qtjava from kdebindings-2.2.2. I
> replaced the qtjava.initialize() with System.loadLibrary("qtjava").
>
> It is possible that GCJ is picking up qtjava classes on your CLASSPATH
> that do not match the ones you compiled into native code?
No, I'm sure I've to the right qtjava.jar to match the lib-org-kde-qt.so 
library. I've tried 4 different versions of gcc/gcj now, and they've all 
failed at the same point in the scribble example code.

> The "ScribbleWindow" also runs and I can "scribble", however selecting
> anything from the menus results in a crash in jni.cc... I havn't tried
> to debug this yet.
Event handling and slots/signals callbacks need to call Java from C++ - the 
bindings save the 'JavaVM *' on initialisation, so that they can use this 
pointer to get an environment to pass to the JNI functions for the callbacks. 
Thomas Kuhn was the first to get the bindings working with gcj, and he found 
with gcj 3.0.0 that this way of getting a 'JNIEnv *' didn't always work in 
the JNI calls. So he changed the callbacks to CNI, which worked fine. Here is 
the code to retrieve the env pointer:

static JavaVM *	_jvm;

void
QtSupport::registerJVM(JNIEnv * env)
{
	env->GetJavaVM((JavaVM **) &_jvm);
...

JNIEnv *
QtSupport::GetEnv()
{
	JNIEnv *	env;

	_jvm->GetEnv((void **) &env, JNI_VERSION_1_2);
	return env;
}

But Adam Dingle got the bindings working with gcc 3.0.4 with no changes to the 
source code. I wonder if the same bug has been reintroduced in gcc 3.1. I'd 
been interested in what's causing the crash - whether or not it's the slot 
callback for the menu selection has retrieved an invalid env pointer from 
QtSupport::GetEnv().

-- Richard



More information about the Java mailing list