[PyKDE] QTextDrag::decode

Phil Thompson phil at river-bank.demon.co.uk
Tue Apr 4 23:06:12 BST 2000

Phil Thompson wrote:
> Pete Ware wrote:
> >
> > QTextDrag::decode () takes two arguments, the second is a Qstring &.
> > To get that to work with PyQt, I did:
> >
> >         x = qt.QString()
> >         qt.QTextDrag.decode (qt.QApplication.clipboard().data(), x)
> >
> > I guess what I expected was for the returned QString to be returned as
> > part of a tuple.
> >
> > Is that a reasonable expectation?  In general, how should modified
> > parameters that are pass by reference be dealt with?
> A perfectly reasonable expectation.  In 99% of cases a class reference
> is passing a value to the function - you just found something that falls
> into the 1%, and I don't go through the thousands of function
> definitions with a fine toothcomb.  In short, a bug.

Thinking about this a bit more, it's less obvious what the right thing
to do is. Returning tuples has to be done when an argument is a pointer
or a reference to a simple type (int, float etc.)  With classes there is
a choice.  If you have a function that uses a class reference argument
to get and update a value, then the current way looks cleaner (and
closer to the original C++), eg...

	s = function_that_returns_a_QString()
	res = function_that_updates_a_QString(s)

...rather than...

	s = function_that_returns_a_QString()
	(res,s) = function_that_updates_a_QString(s)

...but it's inconsistent with...

	i = function_that_returns_an_int()
	(res,i) = function_that_updates_an_int(i)


More information about the PyQt mailing list