[Kde-java] Re: GCJ (Re: Build system for KDE4)
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Mon Jun 20 09:46:55 CEST 2005
On Monday 20 June 2005 10:13, Thomas Zander wrote:
> On Sunday 19 June 2005 22:35, Richard Dale wrote:
> [snip signal/slot discussion]
>
> > On the other hand, I think it's useful to
> > have an option close to the C++ api to make it easy to convert code
> > from C++ to java.
>
> Realistically; how many people will do that?
Pretty much eveyone, because nearly all the documentation for Qt and KDE is
C++ based, including the code snippets. I've found ruby or java programmers
who can't program in C++, can manage to read the docs though. They just need
to learn a few basics like a 'char *', 'QString' and 'QCString' are all
Strings in ruby or java.
> But ok, if the implementation is there, we can use it. No need to throw
> work away.
> I assume the example code you typed uses a base object QObject? Or how
> does an object know the SLOT method in your Java example?
They're defined in Qt.java, which is a superclass of QObject.java:
/** Prepend a '2' to a signal string and remove any spaces */
public static String SIGNAL(String signal) {
return "2" + sqeezeOut(signal, ' ');
}
/** Prepend a '1' to a slot string and remove any spaces */
public static String SLOT(String slot) {
return "1" + sqeezeOut(slot, ' ');
}
emit() is defined in QObject.java:
public native void emit(String signal, Object[] args);
protected void emit(String signal) {
Object[] args = new Object[0];
emit("2" + signal.trim() + "()", args);
}
protected void emit(String signal, Object value) {
Object[] args = new Object[1];
args[0] = value;
emit("2" + signal.trim() + "(" + value.getClass().getName() + ")", args);
}
...
There are lots of different overloaded methods for the various arg types, and
just one native method that they all map onto.
I would like to change it to look like this:
protected Proxy emit();
There would be a version in each subclass of QObject. The interfaces supported
by the Proxy returned by emit() would be all the <classname>Signals.java
interfaces for the class and it's superclasses. QPopupMenu has a signals
interface like this:
public interface QPopupMenuSignals {
void activated(int itemId);
void highlighted(int itemId);
void activatedRedirect(int itemId);
void highlightedRedirect(int itemId);
void aboutToShow();
void aboutToHide();
}
So to emit a signal from a subclass of QPopupMenu, you would cast the Proxy to
the appropriate interface:
((QPopupMenuSignals) emit()).activate(3)
Instead of the signal name being a string, it is a method in an interface, and
the emit call is type safe and can be checked at compile time.
-- Richard
More information about the Kde-java
mailing list