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: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

deleteLater, not working

I'm following the ShareFile sample, to share content via invocation but when i close the app (only if i used invocations) i get a ton of these, for every element in the invocation pop up

 

ERROR: Context: Object name=" "ActionItem" " [objectId= 347 ] not unrealized

 the sample deletes the event 

connect(invocation, SIGNAL(armed()), this, SLOT(onArmed()));
	connect(invocation, SIGNAL(finished()), invocation, SLOT(deleteLater()));

 I've tried that as well as deleting the invocation in the destructor but still enconter the same error.

AppUI::~AppUI() {
   delete invocation;
}

 

I did try changing deleteLater to onFinishied, which successfully deleted the invocation, but in the middle of doing it which isn't ideal.

 

Any other tips on how to handle the deletion before my app exits?

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: deleteLater, not working

[ Edited ]

Hi,

 

The example is a bit overcomplicated.

 Invocation*invocation; is not needed, you can declare it as local variable and access it from onArmed like this:

 

void MainApp::onArmed() {
        Invocation *invocation = qobject_cast<Invocation *>(sender());
	invocation->trigger("bb.action.SHARE");
}

 

The error message is saying that ActionItems aren't deleted. Are you assigning a parent to them?

 

deleteLater() should work correctly in the code above. You can create an explicitly defined slot such as onFinished() and call deleteLater() from it, but it will work the same way.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: deleteLater, not working

[ Edited ]

my invocation looks like this

 

Invocation* invocation;

void ApplicationUI::message(QString text) {

	invocation = Invocation::create(
			InvokeQuery::create()
				.parent(this)
				.mimeType("text/plain")
				.uri(text.toUtf8()));

	connect(invocation, SIGNAL(armed()), this, SLOT(onArmed()));
	connect(invocation, SIGNAL(finished()), invocation, SLOT(QObject::deleteLater()));

}

void ApplicationUI::onArmed() {
	invocation->trigger("bb.action.SHARE");
}

 it says more than actionItems, containers, labels etc... everything that made up the invocation pop-up sheet because it's not being deleted before my application calls quit

Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: deleteLater, not working

I setup the onFinished to call invocation->deleteLater(); and noticed this in the log right after

Context: Failed to find target node with id 346 .... how do i find what id 346 is?
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: deleteLater, not working

[ Edited ]

I think MOC won't parse this syntax: SLOT(QObject::deleteLater())
Replace it with SLOT(deleteLater())

You can verify that connect() connected the slot successfully by checking it's return value, it should return true.

 

upd:

[...deleted... nevermind Smiley Happy]

 

Please try fixing the slot declaration. As I said, onFinished slot is not needed unless you want to perform additional actions before destroying the invocation. And it's better to remove the global variable hack and switch to sender(), but it will work 'as is' as well.

 

upd2: the fixed code:

 

void ApplicationUI::message(QString text) {

	Invocation *invocation = Invocation::create(
			InvokeQuery::create()
				.parent(this)
				.mimeType("text/plain")
				.uri(text.toUtf8()));

	connect(invocation, SIGNAL(armed()), this, SLOT(onArmed()));
	connect(invocation, SIGNAL(finished()), invocation, SLOT(deleteLater()));

}

void ApplicationUI::onArmed() {
        Invocation *invocation = qobject_cast<Invocation *>(sender());
	invocation->trigger("bb.action.SHARE");
}

 

 

 

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: deleteLater, not working

[ Edited ]

in a new project i produced the same results using my previous onArmed method and yours

also variated these

connect(invocation, SIGNAL(finished()), invocation, SLOT(deleteLater()));

 

connect(invocation, SIGNAL(finished()), this, SLOT(onFinished()));

 i tried the onfinished method because it outputs a custom console.log entry so i knew it fired, which it does, then right after it says it cant connect to object id 17 (in the empty project)

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: deleteLater, not working

Spent the last hour playing with the code. Smiley Happy It seems to be correct. I only moved onArmed to "slots:" section in header file.

 

I'm also getting these errors when closing the app, no workaround I've tried helped. Looks like a bug in the OS. If you have the time please report it in JIRA. I think it's safe to ignore these errors for now.

 

Context: Failed to find target node with id  15

This error message after a call to deleteLater() also seems to be something internal.

 

Also spotted a memory leak: InvokeQuery is parented to application and these instances are accumulating on every call to message() function. This can be avoided by parenting query to Invocation:

void ApplicationUI::message(QString text)
{
	InvokeQuery *query = InvokeQuery::create()
		.mimeType("text/plain")
		.data(text.toUtf8()); 
	Invocation *invocation = Invocation::create(query);
	query->setParent(invocation); // destroy query with invocation
	invocation->setParent(this); // app can be destroyed before onFinished() is called

	connect(invocation, SIGNAL(armed()), this, SLOT(onArmed()));
	connect(invocation, SIGNAL(finished()), this, SLOT(onFinished()));
}

 

 


Andrey Fidrya, @zmeyc on twitter
Highlighted
Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: deleteLater, not working

Thanks Zmey, I'll file the ticket so they can look into it further to see whats actually going on behind the scenes