[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-edu
Subject: Re: [kde-edu]: Problem with QVariant on Rocs project (help request)
From: "Tomaz Canabrava" <tumaix () gmail ! com>
Date: 2008-08-14 12:01:04
Message-ID: 7ebbb4b50808140501k46aaead6ic0d39d0f3edeed4a () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
well, that helped the program not-to-crash, but it still doesn't works.
new code
void FileArea::createNewScript()
{
KTextEditor::Editor *e = _mainWindow->editor();
KTextEditor::Document* d = e -> createDocument(0);
d->setMode("JavaScript");
addScript(d->documentName(), d);
}
void FileArea::addScript(const QString& name, KTextEditor::Document* data)
{
QTreeWidgetItem *scriptItem = new QTreeWidgetItem(_scriptFolder, ScriptRole);
scriptItem->setIcon(0, KIcon("file-new"));
scriptItem->setText(0, name);
scriptItem->setData(0, ScriptRole, data); // ScriptRole = UserType+1
_mainWindow->changeActive(scriptItem);
}
void MainWindow::changeActive(QTreeWidgetItem * item)
{
switch(item->type())
{
case FileArea::ScriptRole : changeActiveScript(item); break; //
UserType + 1
case FileArea::GraphRole : changeActiveGraph(item); break; //
UserType + 2
}
}
void MainWindow::changeActiveScript(QTreeWidgetItem *item)
{
KTextEditor::Document *d = 0;
//! NEVER GETS INSIDE OF THE IF.
//! Cannot Convert the data to a KTextEditor::Document*
//! But the data *IS* a KTextEditor::Document*
//! =/ *frustrated*
if (item->data(0,FileArea::ScriptRole).canConvert<KTextEditor::Document*>()
) {
d = item->data(0, FileArea::ScriptRole).value<KTextEditor::Document*>();
_scriptingArea -> setDocument( d );
guiFactory()->addClient(_scriptingArea->view());
}
// _scriptingArea -> setDocument(0); outside of the if will work,
// and create a new document, but I want to restore a previously created one.
// any help is apreciated.
}
On Wed, Aug 13, 2008 at 4:33 PM, Andreas Ramm <psychobrain@gmx.net> wrote:
> Try using item->data(0,
> FileArea::ScriptRole)).value<KTextEditor::Document*>()
> to access your data and item->data(0,
> FileArea::ScriptRole)).canConvert<KTextEditor::Document*>() to check if you
> actually have that type inside QVariant. Note the template syntax in both
> of
> those methods. Other helpful methods when dealing with QVariant are type()
> and typeName() which help you finding out what a QVariant contains.
>
> Andreas
>
> On Thu, 14 Aug 2008 02:52:48 am Tomaz Canabrava wrote:
> > I'v spend all morning working on Rocs trying to implement a
> multi-document
> > panel interface,
> > almost everything is good, but this little piece of code here is somewhat
> > broken,
> > my head hurts, anybody can show some light on this, pretty please, with
> > sugar on top?
> >
> > void FileArea::createNewScript(){
> > KTextEditor::Editor *e = _mainWindow->editor();
> > KTextEditor::Document* d = e -> createDocument(0);
> > d->setMode("JavaScript");
> > addScript(d->documentName(), d);
> > }
> >
> > void FileArea::addScript(const QString& name, KTextEditor::Document*
> data){
> > QTreeWidgetItem *scriptItem = new QTreeWidgetItem(_scriptFolder);
> > scriptItem->setIcon(0, KIcon("file-new"));
> > scriptItem->setText(0, name);
> > scriptItem->setData(0, ScriptRole, data);
> > _mainWindow->changeActive(scriptItem);
> > }
> >
> > void MainWindow::changeActiveScript(QTreeWidgetItem *item){
> > KTextEditor::Document *d = item->data(0, FileArea::ScriptRole));
> > _scriptingArea->setDocument( d );
> > guiFactory()->addClient(_scriptingArea->view());
> > }
> >
> > ERROR:
> >
> > cannot convert 'QVariant' to 'KTextEditor::Document*' in initialization
> > the line KTextEditor::Document *d = item->data(0,
> > FileArea::ScriptRole)); gives me a QVariant,
> > I'v tried to qobject_cast<KTextEditor*>(item->data(0,
> > FileArea::ScriptRole)); but also without luck.
> >
> > Anybody can give-me some light? i'm stuck here almost all morning.
>
>
> _______________________________________________
> kde-edu mailing list
> kde-edu@mail.kde.org
> https://mail.kde.org/mailman/listinfo/kde-edu
>
--
Um Computador sem Windows é como um Navio sem dançarinas de Can-Can
[Attachment #5 (text/html)]
<div dir="ltr">well, that helped the program not-to-crash, but it still doesn't \
works.<br>new code<br><pre class="code" id="codemain"><span \
class="keyword">void</span> FileArea::createNewScript()<br>{<br> \
KTextEditor::Editor *e = _mainWindow->editor();<br> KTextEditor::Document* d = e \
-> createDocument(0);<br> d->setMode(<span \
class="literal">"JavaScript"</span>);<br> addScript(d->documentName(), \
d);<br>}<br> <br><span class="keyword">void</span> FileArea::addScript(<span \
class="keyword">const</span> QString& name, KTextEditor::Document* data)<br> \
{<br> QTreeWidgetItem *scriptItem = <span class="keyword">new</span> \
QTreeWidgetItem(_scriptFolder, ScriptRole);<br> scriptItem->setIcon(0, \
KIcon(<span class="literal">"file-new"</span>));<br> \
scriptItem->setText(0, name);<br> scriptItem->setData(0, ScriptRole, data); // \
ScriptRole = UserType+1<br> \
_mainWindow->changeActive(scriptItem);<br>}<br> <br><span \
class="keyword">void</span> MainWindow::changeActive(QTreeWidgetItem * item)<br> \
{<br> <span class="keyword">switch</span>(item->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> <br> <br> <br><span class="keyword">void</span> \
MainWindow::changeActiveScript(QTreeWidgetItem *item)<br>{<br> KTextEditor::Document \
*d = 0;<br> <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> <br> <span class="keyword">if</span> \
(item->data(0,FileArea::ScriptRole).canConvert<KTextEditor::Document*>() ) \
{<br> d = item->data(0, \
FileArea::ScriptRole).value<KTextEditor::Document*>();<br> _scriptingArea \
-> 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 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"><<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;">Try using item->data(0, \
FileArea::ScriptRole)).value<KTextEditor::Document*>()<br> to access your data \
and item->data(0,<br> \
FileArea::ScriptRole)).canConvert<KTextEditor::Document*>() 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>
> I'v spend all morning working on Rocs trying to implement a \
multi-document<br> > panel interface,<br>
> almost everything is good, but this little piece of code here is somewhat<br>
> 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* \
data){<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>
</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>
_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic