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