<div dir="ltr">it&#39;s &#39;bool&#39;<br>don&#39;t know why, maybe KTextEditor::Document doesn&#39;t extends QVariant (or has a enum { Type } )<br><br>I changed the behavior and now it works, i&#39;m saving as an int that represents the pos on a QList.<br>
<br><br><br><div class="gmail_quote">On Thu, Aug 14, 2008 at 5:11 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;">
What does it say, when qDebug() &lt;&lt;<br>
item-&gt;data(0,FileArea::ScriptRole).typeName()?<br>
<br>
There might be a typedef somewhere which would cause problems so it&#39;s good to<br>
get the type as QVariant sees it.<br>
<div><div></div><div class="Wj3C7c"><br>
On Thu, 14 Aug 2008 10:01:04 pm Tomaz Canabrava wrote:<br>
&gt; well, that helped the program not-to-crash, but it still doesn&#39;t works.<br>
&gt; new code<br>
&gt;<br>
&gt; void FileArea::createNewScript()<br>
&gt; {<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; {<br>
&gt; &nbsp; &nbsp;QTreeWidgetItem *scriptItem = new QTreeWidgetItem(_scriptFolder,<br>
&gt; ScriptRole); 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); // ScriptRole = UserType+1<br>
&gt; &nbsp; &nbsp; _mainWindow-&gt;changeActive(scriptItem);<br>
&gt; }<br>
&gt;<br>
&gt; void MainWindow::changeActive(QTreeWidgetItem * item)<br>
&gt; {<br>
&gt; &nbsp; switch(item-&gt;type())<br>
&gt; &nbsp; {<br>
&gt; &nbsp; &nbsp; &nbsp;case FileArea::ScriptRole : changeActiveScript(item); break; //<br>
&gt; UserType + 1<br>
&gt; &nbsp; &nbsp; &nbsp;case FileArea::GraphRole &nbsp;: changeActiveGraph(item); &nbsp;break; //<br>
&gt; UserType + 2<br>
&gt; &nbsp; }<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; void MainWindow::changeActiveScript(QTreeWidgetItem *item)<br>
&gt; {<br>
&gt; &nbsp; KTextEditor::Document *d = 0;<br>
&gt;<br>
&gt; &nbsp; //! NEVER GETS INSIDE OF THE IF.<br>
&gt; &nbsp; //! Cannot Convert the data to a KTextEditor::Document*<br>
&gt; &nbsp; //! But the data *IS* a KTextEditor::Document*<br>
&gt; &nbsp; //! =/ *frustrated*<br>
&gt;<br>
&gt; &nbsp; if<br>
&gt; (item-&gt;data(0,FileArea::ScriptRole).canConvert&lt;KTextEditor::Document*&gt;() )<br>
&gt; {<br>
&gt; &nbsp; &nbsp; d = item-&gt;data(0,<br>
&gt; FileArea::ScriptRole).value&lt;KTextEditor::Document*&gt;(); _scriptingArea -&gt;<br>
&gt; setDocument( d );<br>
&gt; &nbsp; &nbsp; guiFactory()-&gt;addClient(_scriptingArea-&gt;view());<br>
&gt; &nbsp; }<br>
&gt;<br>
&gt; &nbsp; // _scriptingArea -&gt; setDocument(0); outside of the if will work,<br>
&gt; &nbsp; // and create a new document, but I want to restore a previously created<br>
&gt; one. // any help is apreciated.<br>
&gt; }<br>
&gt;<br>
&gt; On Wed, Aug 13, 2008 at 4:33 PM, Andreas Ramm &lt;<a href="mailto:psychobrain@gmx.net">psychobrain@gmx.net</a>&gt; wrote:<br>
&gt; &gt; Try using item-&gt;data(0,<br>
&gt; &gt; FileArea::ScriptRole)).value&lt;KTextEditor::Document*&gt;()<br>
&gt; &gt; to access your data and item-&gt;data(0,<br>
&gt; &gt; FileArea::ScriptRole)).canConvert&lt;KTextEditor::Document*&gt;() to check if<br>
&gt; &gt; you actually have that type inside QVariant. Note the template syntax in<br>
&gt; &gt; both of<br>
&gt; &gt; those methods. Other helpful methods when dealing with QVariant are<br>
&gt; &gt; type() and typeName() which help you finding out what a QVariant<br>
&gt; &gt; contains.<br>
&gt; &gt;<br>
&gt; &gt; Andreas<br>
&gt; &gt;<br>
&gt; &gt; On Thu, 14 Aug 2008 02:52:48 am Tomaz Canabrava wrote:<br>
&gt; &gt; &gt; I&#39;v spend all morning working on Rocs trying to implement a<br>
&gt; &gt;<br>
&gt; &gt; multi-document<br>
&gt; &gt;<br>
&gt; &gt; &gt; panel interface,<br>
&gt; &gt; &gt; almost everything is good, but this little piece of code here is<br>
&gt; &gt; &gt; somewhat broken,<br>
&gt; &gt; &gt; my head hurts, anybody can show some light on this, pretty please, with<br>
&gt; &gt; &gt; sugar on top?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; void FileArea::createNewScript(){<br>
&gt; &gt; &gt; &nbsp; &nbsp;KTextEditor::Editor *e = _mainWindow-&gt;editor();<br>
&gt; &gt; &gt; &nbsp; &nbsp;KTextEditor::Document* d = e -&gt; createDocument(0);<br>
&gt; &gt; &gt; &nbsp; &nbsp;d-&gt;setMode(&quot;JavaScript&quot;);<br>
&gt; &gt; &gt; &nbsp; &nbsp;addScript(d-&gt;documentName(), d);<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; void FileArea::addScript(const QString&amp; name, KTextEditor::Document*<br>
&gt; &gt;<br>
&gt; &gt; data){<br>
&gt; &gt;<br>
&gt; &gt; &gt; &nbsp; &nbsp;QTreeWidgetItem *scriptItem = new QTreeWidgetItem(_scriptFolder);<br>
&gt; &gt; &gt; &nbsp; &nbsp;scriptItem-&gt;setIcon(0, KIcon(&quot;file-new&quot;));<br>
&gt; &gt; &gt; &nbsp; &nbsp;scriptItem-&gt;setText(0, name);<br>
&gt; &gt; &gt; &nbsp; &nbsp;scriptItem-&gt;setData(0, ScriptRole, data);<br>
&gt; &gt; &gt; &nbsp; _mainWindow-&gt;changeActive(scriptItem);<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; void MainWindow::changeActiveScript(QTreeWidgetItem *item){<br>
&gt; &gt; &gt; &nbsp; KTextEditor::Document *d = item-&gt;data(0, FileArea::ScriptRole));<br>
&gt; &gt; &gt; &nbsp; _scriptingArea-&gt;setDocument( d );<br>
&gt; &gt; &gt; &nbsp; guiFactory()-&gt;addClient(_scriptingArea-&gt;view());<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; ERROR:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; cannot convert &#39;QVariant&#39; to &#39;KTextEditor::Document*&#39; in initialization<br>
&gt; &gt; &gt; the line &nbsp; KTextEditor::Document *d = item-&gt;data(0,<br>
&gt; &gt; &gt; FileArea::ScriptRole)); gives me a QVariant,<br>
&gt; &gt; &gt; I&#39;v tried to qobject_cast&lt;KTextEditor*&gt;(item-&gt;data(0,<br>
&gt; &gt; &gt; FileArea::ScriptRole)); but also without luck.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Anybody can give-me some light? i&#39;m stuck here almost all morning.<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; kde-edu mailing list<br>
&gt; &gt; <a href="mailto:kde-edu@mail.kde.org">kde-edu@mail.kde.org</a><br>
&gt; &gt; <a href="https://mail.kde.org/mailman/listinfo/kde-edu" target="_blank">https://mail.kde.org/mailman/listinfo/kde-edu</a><br>
<br>
<br>
_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Um Computador sem Windows é como um Navio sem dançarinas de Can-Can<br>
</div>