Thanks Stefan,<div><br></div><div>Just confirming for complete clarity ...</div><div><br></div><div>So <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">TW.</span><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); ">.</span></font><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">deleteLater(</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">showMoreDialogue</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">);</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, sans-serif">Must be ... ?<br></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><br>
</font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-size: 13px; background-color: rgb(255, 255, 255); "> showMoreDialogue.</span></font><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">deleteLater(</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">);</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif">Your .odt notes to me late last year (now in Scripting Api) noted to leave TW.deleteLater() alone ( <a href="http://twscript.paulanorman.com/docs/html/files/deleteLater.html">http://twscript.paulanorman.com/docs/html/files/deleteLater.html</a> ), I got confused when trying to work out how to get rid of dialogues.</font></span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: arial; font-size: small; ">> Just a word of caution: as discussed before, connecting to signals is not guaranteed to </span></span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="font-family: arial; font-size: small; ">> be stable ATM.</span></span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">For me, afaik, no problem with signals ever so far ever since UI became available in Scripting.</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; background-color: rgb(255, 255, 255); ">Especially using the Qt supplied connection model style in last email:</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br>
</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "> eval("convertImage.finished." + connectAction + "(dialog_finished)");</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">I haven't tried the other way.</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">> </span>and doesn't cover some cases, where dialogs would be created on-the-fly based on user input</div>
<div><br></div><div>Ok, created and deleted locally in creating function then? </div><div><br></div><div>Or when needed to be used in other functions once created, could just declare the var global say as a string = "I'm not a dialogue yet", not know whether the User initialised it or not as a dialogue, and at finalisation test the global var's .toString().indexOf() for either the dialogue QDialog className or "I'm not a dialogue yet", if appropriate then run .deleteLater() on it during Script finalisation?</div>
<div><br></div><div>Otherwise if being used in more than one function once the User has made it, you'd never know whether and when to deletLater() on it or not. Could also test for initialisation on "I'm not a dialogue yet" in any function that wants to use it calling a function to do that test which can then create it if necessary?</div>
<div><br></div><div>Note: I think a created scriptDialogueName.toString() call should give a string including the className of QDialog, and the name= of the object.</div><div><br></div><div>> <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "> e.g., dialogs could be kept in TW.globals for later use.</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif">Had tried that when Script UI first came out, and thought it didn't work (might have to retry and make sure I got it right). Really like the idea!</font></span></div>
<div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif">Thanks,</font></span></div>
<div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif">Paul</font></span></div>
<div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif"><br></font></span></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" face="arial, sans-serif"><br>
</font></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">Paul</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br></font><div class="gmail_quote">On 20 June 2011 23:13, Stefan Löffler <span dir="ltr"><<a href="mailto:st.loeffler@gmail.com">st.loeffler@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><u></u>
<div bgcolor="#ffffff" text="#000000">
Hi,<div class="im"><br>
<br>
On 2011-06-20 08:17, Paul A Norman wrote:
<blockquote type="cite">Appreciate any suggestions, warnings, about what I am
doing here.... running through it for long term understanding ...
naively was not expecting to hit these issues with just Scripting.</blockquote>
<br></div>
Exclamations of warnings below ;).<br>
Well, scripting is powerful - even more so in combination with C++,
but of course there are also hidden dangers...<br>
<br>
<blockquote type="cite">TW.deleteLater(showMoreDialogue);</blockquote>
<br>
This deletes the TW object! The deleteLater() method is invoked from
its own object and doesn't take any arguments (thought ECMA is quite
lenient when it comes to the question of the number and types of
arguments, so it apparently doesn't complain here).<div class="im"><br>
<br>
<blockquote type="cite">
<div>
<p style="margin:0px;text-indent:0px">
<br>
</p>
<p style="margin:0px;text-indent:0px">}</p>
<p style="margin:0px;text-indent:0px">
<br>
</p>
<p style="margin:0px;text-indent:0px">If a later call, in
the same Script session, to myFunction() tries to do the
following again,</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px;text-indent:0px">
var showMoreDialogue = TW.createUI(scriptPath +
"showMore.ui");</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px;text-indent:0px">
Debugger says,</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px;text-indent:0px">
<font color="#cc6600">Uncaught
exception at
G:/latexportable/LaTexUtils/TeXWorks/texworks/config/scripts/Image
Handling/convertImage.js:304: Error: cannot access member
`createUI' of deleted QObject</font></p>
<p style="margin:0px;text-indent:0px"><font color="#cc6600">304 var
showMoreDialogue = TW.createUI(scriptPath + "showMore.ui");</font></p>
</div>
</blockquote>
<br></div>
It says here "<font color="#cc6600">cannot
access member [...] of deleted QObject</font>" - this means that
you can't call member functions of the TW object anymore because
that has been destroyed (though, normally, this should be
impossible, *unless* of course you're mixing event loops - which can
be a side effect of nesting dialogs; technicallities @
<a href="http://doc.trolltech.com/4.7/qobject.html#deleteLater" target="_blank">http://doc.trolltech.com/4.7/qobject.html#deleteLater</a>). So you've
effectively nuked your connection to Tw ;).<div class="im"><br>
<br>
<blockquote type="cite">
<div>
<p style="margin:0px;text-indent:0px">
So recognising that the Main dialogue emits a signal
".finished"</p>
</div>
</blockquote>
<br></div>
Just a word of caution: as discussed before, connecting to signals
is not guaranteed to be stable ATM.<div class="im"><br>
<br>
<blockquote type="cite">
<div>Does TW.deleteLater() worry :) if it is dealing with is a
script variable that never actually got made into a dialogue
(depending upon User's choices)?
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px;text-indent:0px">
I don't get debugger messages ... but then it may be to far up
the chain to get a Script debugger message? </p>
<p style="margin:0px;text-indent:0px">
<br>
</p>
<p style="margin:0px;text-indent:0px">Am I ok with this or
should I test for className on objects ( more involved --
Script folding back to using QObject .toString() ) and if
they don't have one, then not deleteLater() them?</p>
</div>
</blockquote>
<br></div>
I can't tell off-hand. One thing that is sure is that it's safe to
call deleteLater() multiple times. Note that deleteLater() implies
that the object is not deleted immediately, but is scheduled for
deletion when the control returns to the event loop. Normally, this
is when the script ends (then, control returns to the main event
loop), but dialogs can have their own event loops (so they can run
modally), and in that case things might be more difficult.<br>
The more difficult question is what happens if a variable is
"declared", but is not a QObject. So, e.g., what happens if you say<br>
var a = "test";<br>
a.deleteLater();<br>
I'd naively think that this causes an error, but depending on the
implementation it might not (e.g., if all types are implicitly
derived of or castable to QObject).<br>
<br>
Generally, though, I'm inclined to think that if there are no
errors/messages, the implementation probably handles everything
behind the scenes silently correctly.<div class="im"><br>
<br>
<blockquote type="cite">
<div>
<p style="margin:0px;text-indent:0px">
Or is no debugger message sufficient - no worries mate?
(that's Aussie talk)</p>
</div>
</blockquote>
<br></div>
Yeah, I'd go with "no worries mate" ;).<div class="im"><br>
<br>
<blockquote type="cite">
<div>
<p style="margin:0px;text-indent:0px">
This will be no surprise to you, but I was pleasantly
surprised that using global variable names for the dialogues,
meant that exec() called on them any where after creation and
closing, would re-present the dialogue in the same state as
last used.</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px">Which gives another (more preferable?)
option which I am running with at present:--</p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">Create all dialogues in script
initialisation and immediately call .setVisible(false) ( and
no exec() at that time obviously ) then just .exec() them
when/as needed?</p>
<p style="margin:0px"> </p>
<p style="margin:0px">And destroy them all on main dialogue
. finished() </p>
<p style="margin:0px"><br>
</p>
<p style="margin:0px">I was avoiding this to keep memory usage
down ( (re-)creating them on demand ), but doing this seems
stable and ok, and so far no memory issues at all. </p>
<p style="margin:0px">Only seems to use 0.01 Gb pagefile for
all four dialogues which is more than ok.</p>
<p style="margin:0px;text-indent:0px">
<br>
</p>
<p style="margin:0px;text-indent:0px">Only draw back is a
little screen flicker as the main.first dialogue opens and the
other three open and hide.</p>
<p style="margin:0px;text-indent:0px"><br>
</p>
<p style="margin:0px;text-indent:0px">
Any problems with this last approach at all? - it seems the
tidiest.</p>
</div>
</blockquote>
<br></div>
It's certainly tidy, but requires a lot of book-keeping (and doesn't
cover some cases, where dialogs would be created on-the-fly based on
user input). Plus, there is the flickering.<br>
<br>
So, all in all, I guess the first solution is the more general
solution, but then again this is probably just a matter of taste.<div class="im"><br>
<br>
<blockquote type="cite">
<div>
<p style="margin:0px;text-indent:0px">
Just another question, I get the sense the way the debugger
was responding that a created dialogue is potentially still
around perhaps even after a Script closes?</p>
<p style="margin:0px;text-indent:0px">
If so are they available to Script later? Or does
Script finalisation end their lives?</p>
</div>
</blockquote>
<br></div>
Yes, maybe, and no (actually, these were 3 questions ;)); as I tried
to point out in my previous mail, dialogs are not tied to the
script, and it is the responsibility of the script that creates it
to ensure that they get deleted properly. That said, this doesn't
necessarily happen during the lifetime of the script. You must make
sure you keep a reference to it, though, as the variables to use the
dialog don't survive; e.g., dialogs could be kept in TW.globals for
later use.<br>
<br>
HTH<br>
Stefan<br>
</div>
</blockquote></div><br></div>