From kde-edu-devel Thu Aug 14 23:15:48 2008 From: "Tomaz Canabrava" Date: Thu, 14 Aug 2008 23:15:48 +0000 To: kde-edu-devel Subject: Re: [kde-edu]: Problem with QVariant on Rocs project (help request) Message-Id: <7ebbb4b50808141615s6f0e2d92m9256e5436baa3ba2 () mail ! gmail ! com> X-MARC-Message: https://marc.info/?l=kde-edu-devel&m=121875580809136 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1478461279==" --===============1478461279== Content-Type: multipart/alternative; boundary="----=_Part_5833_22215766.1218755748074" ------=_Part_5833_22215766.1218755748074 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline it's 'bool' don't know why, maybe KTextEditor::Document doesn't extends QVariant (or ha= s a enum { Type } ) I changed the behavior and now it works, i'm saving as an int that represents the pos on a QList. On Thu, Aug 14, 2008 at 5:11 PM, Andreas Ramm wrote: > What does it say, when qDebug() << > item->data(0,FileArea::ScriptRole).typeName()? > > There might be a typedef somewhere which would cause problems so it's goo= d > to > get the type as QVariant sees it. > > On Thu, 14 Aug 2008 10:01:04 pm Tomaz Canabrava wrote: > > well, that helped the program not-to-crash, but it still doesn't works. > > new code > > > > void FileArea::createNewScript() > > { > > KTextEditor::Editor *e =3D _mainWindow->editor(); > > KTextEditor::Document* d =3D e -> createDocument(0); > > d->setMode("JavaScript"); > > addScript(d->documentName(), d); > > } > > > > void FileArea::addScript(const QString& name, KTextEditor::Document* > data) > > { > > QTreeWidgetItem *scriptItem =3D new QTreeWidgetItem(_scriptFolder, > > ScriptRole); scriptItem->setIcon(0, KIcon("file-new")); > > scriptItem->setText(0, name); > > scriptItem->setData(0, ScriptRole, data); // ScriptRole =3D 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 =3D 0; > > > > //! NEVER GETS INSIDE OF THE IF. > > //! Cannot Convert the data to a KTextEditor::Document* > > //! But the data *IS* a KTextEditor::Document* > > //! =3D/ *frustrated* > > > > if > > (item->data(0,FileArea::ScriptRole).canConvert(= ) > ) > > { > > d =3D item->data(0, > > FileArea::ScriptRole).value(); _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 > wrote: > > > Try using item->data(0, > > > FileArea::ScriptRole)).value() > > > to access your data and item->data(0, > > > FileArea::ScriptRole)).canConvert() 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 =3D _mainWindow->editor(); > > > > KTextEditor::Document* d =3D e -> createDocument(0); > > > > d->setMode("JavaScript"); > > > > addScript(d->documentName(), d); > > > > } > > > > > > > > void FileArea::addScript(const QString& name, KTextEditor::Document= * > > > > > > data){ > > > > > > > QTreeWidgetItem *scriptItem =3D new QTreeWidgetItem(_scriptFolde= r); > > > > 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 =3D 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 =3D item->data(0, > > > > FileArea::ScriptRole)); gives me a QVariant, > > > > I'v tried to qobject_cast(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 > > > _______________________________________________ > kde-edu mailing list > kde-edu@mail.kde.org > https://mail.kde.org/mailman/listinfo/kde-edu > --=20 Um Computador sem Windows =E9 como um Navio sem dan=E7arinas de Can-Can ------=_Part_5833_22215766.1218755748074 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
it's 'bool'
don't know why, maybe KText= Editor::Document doesn't extends QVariant (or has a enum { Type } )
=
I changed the behavior and now it works, i'm saving as an int that = represents the pos on a QList.



On Thu, Aug 14, 2008 at 5:11 PM, And= reas Ramm <psyc= hobrain@gmx.net> wrote:
What does it say, when qDebug() <<
item->data(0,FileArea::ScriptRole).typeName()?

There might be a typedef somewhere which would cause problems so it's g= ood to
get the type as QVariant sees it.

On Thu, 14 Aug 2008 10:01:04 pm Tomaz Canabrava wrote:
> well, that helped the program not-to-crash, but it still doesn't w= orks.
> new code
>
> void FileArea::createNewScript()
> {
>    KTextEditor::Editor *e =3D _mainWindow->editor();
>    KTextEditor::Document* d =3D e -> createDocument(0); >    d->setMode("JavaScript");
>    addScript(d->documentName(), d);
> }
>
> void FileArea::addScript(const QString& name, KTextEditor::Documen= t* data)
> {
>    QTreeWidgetItem *scriptItem =3D new QTreeWidgetItem(_scri= ptFolder,
> ScriptRole); scriptItem->setIcon(0, KIcon("file-new")); >    scriptItem->setText(0, name);
>    scriptItem->setData(0, ScriptRole, data); // ScriptRol= e =3D UserType+1
>     _mainWindow->changeActive(scriptItem);
> }
>
> void MainWindow::changeActive(QTreeWidgetItem * item)
> {
>   switch(item->type())
>   {
>      case FileArea::ScriptRole : changeActiveScript(ite= m); break; //
> UserType + 1
>      case FileArea::GraphRole  : changeActiveGraph= (item);  break; //
> UserType + 2
>   }
> }
>
>
>
> void MainWindow::changeActiveScript(QTreeWidgetItem *item)
> {
>   KTextEditor::Document *d =3D 0;
>
>   //! NEVER GETS INSIDE OF THE IF.
>   //! Cannot Convert the data to a KTextEditor::Document*
>   //! But the data *IS* a KTextEditor::Document*
>   //! =3D/ *frustrated*
>
>   if
> (item->data(0,FileArea::ScriptRole).canConvert<KTextEditor::Docu= ment*>() )
> {
>     d =3D item->data(0,
> FileArea::ScriptRole).value<KTextEditor::Document*>(); _scriptin= gArea ->
> 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 previousl= y 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 sy= ntax in
> > both of
> > those methods. Other helpful methods when dealing with QVariant a= re
> > type() and typeName() which help you finding out what a QVariant<= br> > > contains.
> >
> > Andreas
> >
> > On Thu, 14 Aug 2008 02:52:48 am Tomaz Canabrava wrote:
> > > I'v spend all morning working on Rocs trying to implemen= t a
> >
> > multi-document
> >
> > > panel interface,
> > > almost everything is good, but this little piece of code her= e is
> > > somewhat broken,
> > > my head hurts, anybody can show some light on this, pretty p= lease, with
> > > sugar on top?
> > >
> > > void FileArea::createNewScript(){
> > >    KTextEditor::Editor *e =3D _mainWindow->edit= or();
> > >    KTextEditor::Document* d =3D e -> createDocu= ment(0);
> > >    d->setMode("JavaScript");
> > >    addScript(d->documentName(), d);
> > > }
> > >
> > > void FileArea::addScript(const QString& name, KTextEdito= r::Document*
> >
> > data){
> >
> > >    QTreeWidgetItem *scriptItem =3D new QTreeWidget= Item(_scriptFolder);
> > >    scriptItem->setIcon(0, KIcon("file-new&= quot;));
> > >    scriptItem->setText(0, name);
> > >    scriptItem->setData(0, ScriptRole, data); > > >   _mainWindow->changeActive(scriptItem);
> > > }
> > >
> > > void MainWindow::changeActiveScript(QTreeWidgetItem *item){<= br> > > >   KTextEditor::Document *d =3D item->data(0, FileAre= a::ScriptRole));
> > >   _scriptingArea->setDocument( d );
> > >   guiFactory()->addClient(_scriptingArea->view())= ;
> > > }
> > >
> > > ERROR:
> > >
> > > cannot convert 'QVariant' to 'KTextEditor::Docum= ent*' in initialization
> > > the line   KTextEditor::Document *d =3D item->data(0= ,
> > > FileArea::ScriptRole)); gives me a QVariant,
> > > I'v tried to qobject_cast<KTextEditor*>(item->d= ata(0,
> > > FileArea::ScriptRole)); but also without luck.
> > >
> > > Anybody can give-me some light? i'm stuck here almost al= l morning.
> >
> > _______________________________________________
> > kde-edu mailing list
> > kde-edu@mail.kde.org<= br> > > https://mail.kde.org/mailman/listinfo/kde-edu


_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu



--
Um Computad= or sem Windows =E9 como um Navio sem dan=E7arinas de Can-Can
------=_Part_5833_22215766.1218755748074-- --===============1478461279== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kde-edu mailing list kde-edu@mail.kde.org https://mail.kde.org/mailman/listinfo/kde-edu --===============1478461279==--