[PyKDE] QTextBrowser & QMimeSourceFactory

Pete Ware ware at cis.ohio-state.edu
Mon Apr 3 23:10:42 BST 2000


> 
> The call to mimeSourceFactory().data() is what is failing inside the
> second setSource(), and this failing is caused by the first setSource().
> 
> Looking at the comments in the Qt documentation for
> QMimeSourceFactory::data() I'd guess that this is just the way it works
> and not a PyQt problem.
> 
> Phil

Hmm, I don't quite agree but I could easily be misunderstanding.  The
mimeSourceFactory() should be providing a partial map between "href"'s
and the source.  Here is the same example, but shortened.  Looking at
the qt code, I don't see why doing a "setSource()" should change what
"data()" returns.  Even looking at QMimeSourceFactoryData it seems
that the "last" member data keeps leaks from happening.

Output from the script:
1:  <qt.QMimeSource instance at 1716b8>
2:  <qt.QMimeSource instance at 171700>
3:  None

Here is the code in qt/src/widgets/qtextbrowser.cpp:QTextBrowser::setSource()

    if ( !source.isEmpty() && url != d->curmain ) {
	const QMimeSource* m =
		    mimeSourceFactory()->data( source, context() );
	QString txt;
	if ( !m ){
	    qWarning("QTextBrowser: no mimesource for %s", source.latin1() );
	}
	else {
	    if ( !QTextDrag::decode( m, txt ) ) {
		qWarning("QTextBrowser: cannot decode %s", source.latin1() );
	    }
	}

--pete (mystified)

#! /usr/bin/env python
import qt
import sys
 
app = qt.QApplication (sys.argv)
main = qt.QMainWindow ()
 
text = qt.QTextBrowser (main)
 
name1 = qt.QString ('help-start.html')
text1 = qt.QString ('<b>this is a test</b>')
 
text.mimeSourceFactory().setText (name1, text1)
 
print '1: ', text.mimeSourceFactory().data(name1, text.context())
print '2: ', text.mimeSourceFactory().data(name1, text.context())

text.setSource (name1)
# No longer get any data back!
print '3: ', text.mimeSourceFactory().data(name1, text.context())

main.setCentralWidget (text)
app.setMainWidget (main)
 
main.show ()
app.exec_loop ()




More information about the PyQt mailing list