<div dir="ltr">well, that helped the program not-to-crash, but it still doesn&#39;t works.<br>new code<br><pre class="code" id="codemain"><span class="keyword">void</span> FileArea::createNewScript()<br>{<br>   KTextEditor::Editor *e = _mainWindow-&gt;editor();<br>
   KTextEditor::Document* d = e -&gt; createDocument(0);<br>   d-&gt;setMode(<span class="literal">&quot;JavaScript&quot;</span>);<br>   addScript(d-&gt;documentName(), d);<br>}<br>&nbsp;<br><span class="keyword">void</span> FileArea::addScript(<span class="keyword">const</span> QString&amp; name, KTextEditor::Document* data)<br>
{<br>   QTreeWidgetItem *scriptItem = <span class="keyword">new</span> QTreeWidgetItem(_scriptFolder, ScriptRole);<br>   scriptItem-&gt;setIcon(0, KIcon(<span class="literal">&quot;file-new&quot;</span>));<br>   scriptItem-&gt;setText(0, name);<br>
   scriptItem-&gt;setData(0, ScriptRole, data); // ScriptRole = UserType+1<br>    _mainWindow-&gt;changeActive(scriptItem);<br>}<br>&nbsp;<br><span class="keyword">void</span> MainWindow::changeActive(QTreeWidgetItem * item)<br>
{<br>  <span class="keyword">switch</span>(item-&gt;type())<br>  {<br>     <span class="keyword">case</span> FileArea::ScriptRole : changeActiveScript(item); <span class="keyword">break</span>; // UserType + 1<br>     <span class="keyword">case</span> FileArea::GraphRole  : changeActiveGraph(item);  <span class="keyword">break</span>; // UserType + 2<br>
  }<br>}<br>&nbsp;<br>&nbsp;<br>&nbsp;<br><span class="keyword">void</span> MainWindow::changeActiveScript(QTreeWidgetItem *item)<br>{<br>  KTextEditor::Document *d = 0;<br>&nbsp;<br>  <span class="comment">//! NEVER GETS INSIDE OF THE IF.<br>
</span>  <span class="comment">//! Cannot Convert the data to a KTextEditor::Document* <br></span>  <span class="comment">//! But the data *IS* a KTextEditor::Document*<br></span>  <span class="comment">//! =/ *frustrated*<br>
</span>&nbsp;<br>  <span class="keyword">if</span> (item-&gt;data(0,FileArea::ScriptRole).canConvert&lt;KTextEditor::Document*&gt;() ) {<br>    d = item-&gt;data(0, FileArea::ScriptRole).value&lt;KTextEditor::Document*&gt;();<br>
    _scriptingArea -&gt; setDocument( d );<br>    guiFactory()-&gt;addClient(_scriptingArea-&gt;view());<br>  }<br><br>  // _scriptingArea -&gt; setDocument(0); outside of the if will work, <br>  // and create a new document, but I want to restore a previously created one. <br>
  // any help is apreciated. <br>}</pre><br><br><br><br><br><div class="gmail_quote">On Wed, Aug 13, 2008 at 4:33 PM, Andreas Ramm <span dir="ltr">&lt;<a href="mailto:psychobrain@gmx.net">psychobrain@gmx.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Try using item-&gt;data(0, FileArea::ScriptRole)).value&lt;KTextEditor::Document*&gt;()<br>
to access your data and item-&gt;data(0,<br>
FileArea::ScriptRole)).canConvert&lt;KTextEditor::Document*&gt;() to check if you<br>
actually have that type inside QVariant. Note the template syntax in both of<br>
those methods. Other helpful methods when dealing with QVariant are type()<br>
and typeName() which help you finding out what a QVariant contains.<br>
<br>
Andreas<br>
<div><div></div><div class="Wj3C7c"><br>
On Thu, 14 Aug 2008 02:52:48 am Tomaz Canabrava wrote:<br>
&gt; I&#39;v spend all morning working on Rocs trying to implement a multi-document<br>
&gt; panel interface,<br>
&gt; almost everything is good, but this little piece of code here is somewhat<br>
&gt; broken,<br>
&gt; my head hurts, anybody can show some light on this, pretty please, with<br>
&gt; sugar on top?<br>
&gt;<br>
&gt; void FileArea::createNewScript(){<br>
&gt; &nbsp; &nbsp;KTextEditor::Editor *e = _mainWindow-&gt;editor();<br>
&gt; &nbsp; &nbsp;KTextEditor::Document* d = e -&gt; createDocument(0);<br>
&gt; &nbsp; &nbsp;d-&gt;setMode(&quot;JavaScript&quot;);<br>
&gt; &nbsp; &nbsp;addScript(d-&gt;documentName(), d);<br>
&gt; }<br>
&gt;<br>
&gt; void FileArea::addScript(const QString&amp; name, KTextEditor::Document* data){<br>
&gt; &nbsp; &nbsp;QTreeWidgetItem *scriptItem = new QTreeWidgetItem(_scriptFolder);<br>
&gt; &nbsp; &nbsp;scriptItem-&gt;setIcon(0, KIcon(&quot;file-new&quot;));<br>
&gt; &nbsp; &nbsp;scriptItem-&gt;setText(0, name);<br>
&gt; &nbsp; &nbsp;scriptItem-&gt;setData(0, ScriptRole, data);<br>
&gt; &nbsp; _mainWindow-&gt;changeActive(scriptItem);<br>
&gt; }<br>
&gt;<br>
&gt; void MainWindow::changeActiveScript(QTreeWidgetItem *item){<br>
&gt; &nbsp; KTextEditor::Document *d = item-&gt;data(0, FileArea::ScriptRole));<br>
&gt; &nbsp; _scriptingArea-&gt;setDocument( d );<br>
&gt; &nbsp; guiFactory()-&gt;addClient(_scriptingArea-&gt;view());<br>
&gt; }<br>
&gt;<br>
&gt; ERROR:<br>
&gt;<br>
&gt; cannot convert &#39;QVariant&#39; to &#39;KTextEditor::Document*&#39; in initialization<br>
&gt; the line &nbsp; KTextEditor::Document *d = item-&gt;data(0,<br>
&gt; FileArea::ScriptRole)); gives me a QVariant,<br>
&gt; I&#39;v tried to qobject_cast&lt;KTextEditor*&gt;(item-&gt;data(0,<br>
&gt; FileArea::ScriptRole)); but also without luck.<br>
&gt;<br>
&gt; Anybody can give-me some light? i&#39;m stuck here almost all morning.<br>
<br>
<br>
</div></div>_______________________________________________<br>
kde-edu mailing list<br>
<a href="mailto:kde-edu@mail.kde.org">kde-edu@mail.kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kde-edu" target="_blank">https://mail.kde.org/mailman/listinfo/kde-edu</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Um Computador sem Windows é como um Navio sem dançarinas de Can-Can<br>
</div>