<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Phil Thompson wrote:
<blockquote cite="mid:59b2a99b898578647f5b7e5e628d1c93@localhost"
type="cite">
<pre wrap="">On Mon, 02 Feb 2009 16:51:28 +0100, GT6 <a class="moz-txt-link-rfc2396E" href="mailto:gt6@gmx.net"><gt6@gmx.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Phil Thompson wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Mon, 02 Feb 2009 16:27:51 +0100, GT6 <a class="moz-txt-link-rfc2396E" href="mailto:gt6@gmx.net"><gt6@gmx.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Phil Thompson wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Mon, 02 Feb 2009 13:49:23 +0100, GT6 <a class="moz-txt-link-rfc2396E" href="mailto:gt6@gmx.net"><gt6@gmx.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Phil Thompson wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Mon, 02 Feb 2009 03:37:13 +0100, GT6 <a class="moz-txt-link-rfc2396E" href="mailto:gt6@gmx.net"><gt6@gmx.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi there.
When running the below sample script, and clicking the button, it
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">will
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">segfault, and I don't understand why or how. I've overwritten a
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">function
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">in QPlainTextEdit and it should create a new document, set the
PlainTextDocumentLayout and then set the document on the
QPlainTextEdit
widget. The important part is this (1st way):
newDoc = QtGui.QTextDocument()
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout(newDoc))
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> self.setDocument(newDoc)
The above segfaults. I also tried this (2nd way):
newDoc = QtGui.QTextDocument()
newDoc.setDocumentLayout(self.documentLayout())
self.setDocument(newDoc)
This one doesn't segfault, but I get this error:
AttributeError: documentLayout
Apart from that, I tried this third option (3rd way):
newDoc = QtGui.QTextDocument()
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout.__init__(newDoc))
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> self.setDocument(newDoc)
with the only difference from the first one being that __init__ is
called explicitly instead of expecting it to be defaultet. This one
_doesn't_ segfault, but gives this error:
QPlainTextEdit::setDocument: Document set does not support
QPlainTextDocumentLayout
Which makes no sense as not calling __init__ directly shouldn't be
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">any
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">different than calling it explicitly.
</pre>
</blockquote>
<pre wrap="">__init__() initialises a class, it doesn't create one.
</pre>
<blockquote type="cite">
<pre wrap="">So, does anyone have any idea why
this is happening? Do you have a bug tracker?
</pre>
</blockquote>
<pre wrap="">Keep a reference to "newDoc" - it is getting garbage collected too
soon.
Phil
</pre>
</blockquote>
<pre wrap="">Thanks for your help.
Well, that only works once. So I replace the plzsegfault function in
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">the
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">sample with this (full sample binned here
</pre>
</blockquote>
<pre wrap=""><a class="moz-txt-link-freetext" href="http://rafb.net/p/P6sqML59.html">http://rafb.net/p/P6sqML59.html</a>):
</pre>
<blockquote type="cite">
<pre wrap=""> def plzsegfault(self):
self.newDoc = QtGui.QTextDocument()
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->self.newDoc.setDocumentLayout(QtGui.QPlainTextDocumentLayout(self.newDoc))
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap=""># First way
self.setDocument(self.newDoc)
Then, I can safely click the button once, and it also does what I
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">expect
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">it to do, but clicking the button a second time will again segfault.
What I'm trying to do is that clicking the button will clear the
textfield and make a new document and display it. Do I really have to
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">care about the document names? I *could* implement a counter and have
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">all the documents have different names but I don't really need those
specific names in the future. I just need the textfield to discard
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->the
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">old one and get a new one, everytime the button is clicked. The only
reference to the document that I use lateron is self.document(). I
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">don't
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">need the name...
</pre>
</blockquote>
<pre wrap="">You might not but Python needs a reference of some sort to stop the
object
being garbage collected.
Your new version is still garbage collecting too soon. Just add the
following to the end of plzsegfault() in your *original* version...
self._doc = newDoc
Phil
</pre>
</blockquote>
<pre wrap="">It's still not working in my "real" application. I've been trying to
figure out what's wrong for hours now but it's just weird and I don't
understand it. Here's the complete code of what I'm doing. It's a small
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">calendar: <a class="moz-txt-link-freetext" href="http://rafb.net/p/rW8qrv26.html">http://rafb.net/p/rW8qrv26.html</a>
</pre>
</blockquote>
<pre wrap="">That's got to be the dumbest pasting site I've ever seen. Why isn't
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->there
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">a
link to download a file?
</pre>
<blockquote type="cite">
<pre wrap="">The code is a bit messy, there are some obsolete things in there. In
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->any
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">case, could you please try the following:
1.) run the script
</pre>
</blockquote>
<pre wrap="">I will if you send it to me as an attachment.
Phil
</pre>
</blockquote>
<pre wrap="">Here you go. Or a direct link: <a class="moz-txt-link-freetext" href="http://stuff.bandruum.ch/pyqal-0.04.py">http://stuff.bandruum.ch/pyqal-0.04.py</a>
</pre>
</blockquote>
<pre wrap=""><!---->
It's still the same problem. Now that you have multiple documents, using a
single "self._doc" to keep the reference is no longer adequate. However the
dict you already have should be used for this.
The attached has a much simplified version of your TextEditEnter class
which seems to work.
Phil
</pre>
</blockquote>
Ah well. Nevermind. I changed the implementation completely to use
sqlite now. Still learning all this, but now it's working without
problems as I reuse the same QTextDocument and only handle content.
It's all plain text anyway.<br>
<br>
Thanks for your help!<br>
Carl.<br>
</body>
</html>