Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

QDeclarativeEngine::setObjectOwnership issue

[ Edited ]

I'm creating a sheet in C++ and then trying to destroy that sheet from within qml.

 

Which returns the following error

 

Error: Invalid attempt to destroy() an indestructible object

 

I came across the following nokia thread about the issue and it suggested the following be applied

 

QDeclarativeEngine::setObjectOwnership(root, QDeclarativeEngine::JavaScriptOwnership);

When I add that I no longer get the error but the sheet is still not destroyed.

 

Any thoughts on what's happening here?

 

C++ Where Sheet is created

        QmlDocument* qml = QmlDocument::create("asset:///SubmitScreen.qml").parent(this);
        Sheet* root = qml->createRootObject<Sheet>();
        QDeclarativeProperty(root, "photoUrl").write(CardDoneMessage.data());
        QDeclarativeEngine::setObjectOwnership(root, QDeclarativeEngine::JavaScriptOwnership);
        root->open();

 QML Where Sheet is destroyed

    onClosed: {
        submitSheet.destroy();
    }
_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: QDeclarativeEngine::setObjectOwnership issue

I had the same problem trying to destroy a couple of Pages that were created from C++ and not from ComponentDefinition. I believe you can only call destroy() on pages or sheets that were created from a ComponentDefinition (but I expect @BBSJdev will correct me Smiley Wink)

 

Anyway, I had to add a Q_INVOKABLE function to my Page that I could call from QML, and all this function does is call deleteLater(). Then I call that function instead of destroy().


Philipk wrote:

I'm creating a sheet in C++ and then trying to destroy that sheet from within qml.

 

Which returns the following error

 

Error: Invalid attempt to destroy() an indestructible object

 

I came across the following nokia thread about the issue and it suggested the following be applied

 

QDeclarativeEngine::setObjectOwnership(root, QDeclarativeEngine::JavaScriptOwnership);

When I add that I no longer get the error but the sheet is still not destroyed.

 

Any thoughts on what's happening here?

 

C++ Where Sheet is created

        QmlDocument* qml = QmlDocument::create("asset:///SubmitScreen.qml").parent(this);
        Sheet* root = qml->createRootObject<Sheet>();
        QDeclarativeProperty(root, "photoUrl").write(CardDoneMessage.data());
        QDeclarativeEngine::setObjectOwnership(root, QDeclarativeEngine::JavaScriptOwnership);
        root->open();

 QML Where Sheet is destroyed

    onClosed: {
        submitSheet.destroy();
    }





Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QDeclarativeEngine::setObjectOwnership issue

[ Edited ]

@greenmr I could wait 30 minutes so you could hear it from someone else that there was a bug in 10.0 but destroying dynamic sheets in QML from 10.1 onwards should be fine. **bleep** I let it out anyway.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: QDeclarativeEngine::setObjectOwnership issue

@BBSJdev I assume you mean to say destroying sheets and not closing them. I'm on 10.1 and it's definitely the case that the sheet is not being destroyed. When I create and open the second sheet I get doubles popping up.
_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QDeclarativeEngine::setObjectOwnership issue

Yes you'll see I changed it when I re-read it myself. Smiley Happy

 

You're also not creating it dynamically either and I believe greenmr is right on that point.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: QDeclarativeEngine::setObjectOwnership issue

If I add the following component defenition, could I find that element using C++ and have the sheet created that way?

 

        ComponentDefinition {
        id: submitPageDef
        source: "asset:///SubmitScreen.qml"
        }

 

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QDeclarativeEngine::setObjectOwnership issue

Yes once it's added to the scene graph you'll be able to access it.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: QDeclarativeEngine::setObjectOwnership issue

Haha, I knew it would be you. Smiley Wink

 

Actually though, I'm not sure we are talking about the same thing, and I probably misunderstood the OP's scenario. In my app I push a C++ defined Page from QML via a ComponentDefinition. Then, from that page, I push ANOTHER C++ defined Page onto the stack, but this time, ComponentDefinition is not used. The original Page just instantiates the second page with new and pushes it directly onto its own parent.

 

in this situation, I am unable to destroy() the second page in the popTransitionEnded slot. If I try I get the Error: Invalid attempt to destroy() an indestructible object message. This is not just a BB10.0 thing, it happens right up to BB10.2. When the OP said they were creating a Sheet in C++ and then trying to destroy it in QML with JavaScript, I thought it was the same situation, but now I'm thinking the OP meant that they define their Sheet in C++ but then instantiate it via ComponentDefinition.createObject(), which is not the same as what I am doing.


BBSJdev wrote:

@greenmr I could wait 30 minutes so you could hear it from someone else that there was a bug in 10.0 but destroying dynamic sheets in QML from 10.1 onwards should be fine. **bleep** I let it out anyway.

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: QDeclarativeEngine::setObjectOwnership issue

@greenmr you were initially correct. I was just asking about an alternative setup which might help to allow me to destroy the sheet.

 

At this point I'm finding similar posts but the solution isn't working for me.

 

QObject::connect(root, SIGNAL(closed()), root, SLOT(deleteLater()));

 from http://supportforums.blackberry.com/t5/Native-Development/dynamic-objects-C-vs-QML/td-p/2480627

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: QDeclarativeEngine::setObjectOwnership issue

Ok, in this case, I don't think the other solutions listed here will fix it for you. I would suggest you take my earlier advice. Create a Q_INVOKABLE C++ function on your Sheet, perhaps something like void destroyLater(). It should look something like this:

 

void MySheet::destroyLater() {
    deleteLater();
}

Now you can do this is QML:

 

onClosed: {
    submitSheet.destroyLater();
}

 



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.