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
Highlighted
Developer
Posts: 102
Registered: ‎04-01-2014
My Device: BlackBerry10 Simulator
My Carrier: none
Accepted Solution

change visibility of Label from C++

Hi.

 

the MainPage of my app contains a container with a ListView filled with an ArrayDataModel defined as a Q_PROPERTY.

There is also a Label on the Page which I want to be invisible when the ArrayDataModel is empty.

 

Would it all be in QML I found this is working. I define the ArrayDataModel in QML like so:

attached Objects: [
  id: theDataModel

  property bool empty: true

  onItemAdded: empty = isEmtpy()
  onItemRemoved: empty = isEmtpy()
  onItemUpdated: empty = isEmtpy()
  onItemsChanged: empty = isEmtpy()

]

 I can't use that here because my ArrayDataModel is defined in C++.

I think I have to use signals and slots. But then I have to write all this signals (like when adding, removing, changed the DataModel) and connect it to the label.

Is this the way I have to go. Or is there a simplier way?

Developer
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: change visibility of Label from C++

you could define your DataModel in QML, but fill it from C++ (several of the tutorials are doing it that way, see e.g. the quotes example).

That way you can still control the visibility of your labels via QML

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Developer
Posts: 102
Registered: ‎04-01-2014
My Device: BlackBerry10 Simulator
My Carrier: none

Re: change visibility of Label from C++

Thanks for the tip. I will try that.

Developer
Posts: 102
Registered: ‎04-01-2014
My Device: BlackBerry10 Simulator
My Carrier: none

Re: change visibility of Label from C++

Thanks works perfectly. I just wrote a function in C++ that fills the ArrayDataModel with elements and gave it the ArrayDataModel als parameter.

In QML:

app.fillDataModel(myDataModel)

 In C++:

fillDataModel(bb::cascades::ArrayDataModel* model){
  
  // In my case I read the informations from QSettings
  QSettings settings;

int size = settings.value("size", 0).toInt();
for (int i = 0; i < size; i++) {
	QString filepath = settings.value("completePath_" + QString::number(i),
			"File not found").toString();
	QVariantMap item = convertPathToListItem(filepath);
	model->append(item);
}