Bug 112409 - overloading qt event handling methods in Java subclasses fails
Summary: overloading qt event handling methods in Java subclasses fails
Status: RESOLVED WORKSFORME
Alias: None
Product: bindings
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kde-bindings
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-11 12:27 UTC by Jochen Becher
Modified: 2023-01-02 05:27 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jochen Becher 2005-09-11 12:27:49 UTC
Version:            (using KDE KDE 3.4.0)
Installed from:    SuSE RPMs
OS:                Linux

The following program defines a widget TestWidget which inherits from QWidget and overloads the event handler mouseReleaseEvent(). It also defines a widget TestWidget2 which inherits from TestWidget and overloads mousePressEvent(). Both widgets should handle the mouseReleaseEvent() but only TestWidget does. If you add a mouseReleaseEvent() to class TestWidget2 which calls the super-method than it works as expected. The calling of Java methods from the C++ wrapper code seems to be broken.


import org.kde.qt.QApplication;
import org.kde.qt.QCloseEvent;
import org.kde.qt.QMouseEvent;
import org.kde.qt.QWidget;
import org.kde.qt.qtjava;

/*
 * Created on 11.09.2005
 *
 */

public class QtTest {

    QApplication app;

    class TestWidget extends QWidget {
        public TestWidget() {
            super();
            resize(100,100);
            show();
        }

        protected void mouseReleaseEvent(QMouseEvent arg0) {
            System.out.println("release");
            super.mouseReleaseEvent(arg0);
        }
    }

    class TestWidget2 extends TestWidget {
        protected void closeEvent(QCloseEvent arg0) {
            System.out.println("quit");
            app.quit();
            super.closeEvent(arg0);
        }
        
        protected void mousePressEvent(QMouseEvent arg0) {
            System.out.println("press");
            super.mousePressEvent(arg0);
        }
        
    }
    
    public QtTest(String[] args) {
        app = new QApplication(args);
        TestWidget w = new TestWidget();
        TestWidget w2 = new TestWidget2();
        app.exec();
    }

    public static void main(String[] args) {
        qtjava.initialize();
        new QtTest(args);
    }

}
Comment 1 Richard Dale 2005-10-06 13:36:29 UTC
SVN commit 467774 by rdale:

* This check via reflection to tell if an event method had been
  overriden was insufficiently herioc - I just love those java
  apis ;). This should fix the bug reported by Jochen Becher

CCBUGS: 112409
CCMAIL: kde-java@kde.org



 M  +8 -4      Invocation.java  


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #467773:467774
@@ -442,11 +442,15 @@
 		Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);
 		
 		try {
-			// Assume that an event handler is a protected method, so use getDeclaredMethod()
-			method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+			method = onThis.getClass().getMethod(methodName, parameterType);
 			method.setAccessible(true);
-		} catch (NoSuchMethodException e) {
-			return false;
+		} catch (NoSuchMethodException e1) {
+			try {
+				method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+				method.setAccessible(true);
+			} catch (NoSuchMethodException e2) {
+				return true;
+			}
 		}
 
 		// Ignore any native code event handling methods
Comment 2 Richard Dale 2005-10-06 13:44:31 UTC
SVN commit 467777 by rdale:

* Oops, the last commit solved the wrong problem. Instead of 
  two nested exception handlers, which would get both 
  protected and public methods, but not inherited ones.
  A loop is needed to look for inherited event methods, going
  up the class heirarchy.

CCBUGS: 112409
CCMAIL: kde-java@kde.org



 M  +8 -7      Invocation.java  


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #467776:467777
@@ -440,18 +440,19 @@
 		Class[] parameterType = new Class[1];
 		parameterType[0] = Class.forName(qtjava.toFullyQualifiedClassName(argClass));
 		Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);
+
+		Class targetClass = onThis.getClass();
 		
-		try {
-			method = onThis.getClass().getMethod(methodName, parameterType);
-			method.setAccessible(true);
-		} catch (NoSuchMethodException e1) {
+		do {
 			try {
-				method = onThis.getClass().getDeclaredMethod(methodName, parameterType);
+				method = targetClass.getDeclaredMethod(methodName, parameterType);
 				method.setAccessible(true);
-			} catch (NoSuchMethodException e2) {
+			} catch (NoSuchMethodException e1) {
 				return true;
 			}
-		}
+			
+			targetClass = targetClass.getSuperclass();
+		} while (targetClass != null);
 
 		// Ignore any native code event handling methods
 		if ((method.getModifiers() & Modifier.NATIVE) != 0) {
Comment 3 Richard Dale 2005-10-06 14:00:33 UTC
SVN commit 467780 by rdale:

* Oops, wrong again. The event invoker should return false
  if it fails, not true
CCBUGS: 112409



 M  +1 -1      Invocation.java  


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #467779:467780
@@ -448,7 +448,7 @@
 				method = targetClass.getDeclaredMethod(methodName, parameterType);
 				method.setAccessible(true);
 			} catch (NoSuchMethodException e1) {
-				return true;
+				return false;
 			}
 			
 			targetClass = targetClass.getSuperclass();
Comment 4 Richard Dale 2005-10-07 15:52:31 UTC
SVN commit 468238 by rdale:

* Still trying to fix bug #112409 - fourth attempt, feeling lucky

CCBUGS: 112409
CCMAIL: kde-java@kde.org



 M  +6 -2      Invocation.java  


--- branches/KDE/3.5/kdebindings/qtjava/javalib/org/kde/qt/Invocation.java #468237:468238
@@ -436,7 +436,7 @@
 		if the method was successfully invoked, otherwise false.
 		Used for event handling callbacks */
 	public static boolean invoke(long target, long arg, String argClass, String methodName) throws NoSuchMethodException, ClassNotFoundException  {
-		Method	method;
+		Method	method = null;
 		Class[] parameterType = new Class[1];
 		parameterType[0] = Class.forName(qtjava.toFullyQualifiedClassName(argClass));
 		Object onThis = qtjava.objectForQtKey(target, "org.kde.qt.QObject", false);
@@ -447,13 +447,17 @@
 			try {
 				method = targetClass.getDeclaredMethod(methodName, parameterType);
 				method.setAccessible(true);
+				break;
 			} catch (NoSuchMethodException e1) {
-				return false;
 			}
 			
 			targetClass = targetClass.getSuperclass();
 		} while (targetClass != null);
 
+		if (targetClass == null) {
+			return false;
+		}
+
 		// Ignore any native code event handling methods
 		if ((method.getModifiers() & Modifier.NATIVE) != 0) {
 			return false;
Comment 5 Andrew Crouthamel 2018-11-02 04:20:48 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Andrew Crouthamel 2018-11-16 02:36:12 UTC
Dear Bug Submitter,

This is a reminder that this bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version?

Thank you for helping us make KDE software even better for everyone!
Comment 7 Justin Zobel 2022-12-03 09:01:34 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 8 Bug Janitor Service 2022-12-18 05:13:56 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 9 Bug Janitor Service 2023-01-02 05:27:48 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!