[PyKDE] PyQt-3.1rc2: problem with connections (+patch)

Rene Hogendoorn rene.hogendoorn at hccnet.nl
Mon Mar 18 23:01:22 GMT 2002


pyuic only generates connection statements correctly for slot functions without arguments,
i.e. it assumes that the slot function is a python function.
If the slot function has any arguments, the resulting connection will be to a C++-function,
although the python slot function template is (correctly) generated.
Example:

self.connect(self.ClientName,SIGNAL("textChanged(const QString&)"),self,SLOT("ClientName_textChanged(const QString&)"))

is generated, while the function definition is

def ClientName_textChanged(self,a0):
    print "AddClientWizardGUI.ClientName_textChanged( const QString & ): Not implemented yet"

The problem is designer. Designer generates different signatures for the slot function in
connection declarations and in slot declarations. In particular, the slot declaration
uses spaces to separate function arguments, whereas the connection declaration does not.

The following patch is a workaround (until designer is patched)

Index: form.cpp
===================================================================
RCS file: /home/cvs/public/PyQt/pyuic3/form.cpp,v
retrieving revision 1.9
diff -u -r1.9 form.cpp
--- form.cpp	12 Mar 2002 19:31:13 -0000	1.9
+++ form.cpp	18 Mar 2002 21:41:28 -0000
@@ -571,11 +571,31 @@
 		    << ",SIGNAL(\"" << signal << "\"),";
 
 		// See if this is a user defined slot.
+		// slot and connection declarations use different function signatures
+		// for slot functions; patch the connection declaration
  
 		bool isUserSlot = FALSE;
- 
+		QString patched_slot( "" );
+		for ( unsigned int j = 0; j < slot.length(); j++ ) {
+		   if (slot[j] == '(') {
+		      // add space after
+		      patched_slot += "( ";
+		   }
+		   else {
+		      if (slot[j] == '&' ||
+			  slot[j] == '*' ||
+			  slot[j] == ')') {
+
+			 // add space before
+			 patched_slot += " ";
+		      }
+
+		      patched_slot += slot[j];
+		   }
+		}
+		   
 		for (it = extraSlots.begin(); it != extraSlots.end(); ++it) {
-		    if (*it == slot) {
+		    if (*it == patched_slot) {
 			isUserSlot = TRUE;
 			break;
 		    }


Regards




More information about the PyQt mailing list