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
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
Accepted Solution

Listview not loading datamodel

[ Edited ]

Hello all, been trying to make a page which when pushed display a listview with data populated by a groupdatamodel from a SQL database. This only seems to work if the scene of the application is set to the page with the ListView, with Application::setScene(listPage);

 

If I instead have a different page defined here and the listView page is pushed by the other page, it does not populate the list. I will show an example:

 

App::App()
{

	QCoreApplication::setOrganizationName("testName");
	QCoreApplication::setApplicationName("testApp");
	 qml = QmlDocument::create().load("main.qml");
	   qml->setParent(this); 

	      if (!qml->hasErrors()) {
	    	  TabbedPane *tabs = qml->createRootNode<TabbedPane();
          
            	qml->setContextProperty("contextProperty", this);
                createSongsPage();
                if (tabs) {
                Application::setScene(tabs);
                }
            }
}

 Then I can switch tabs to the songsPage which has my list and was created like this:

 

void App::createSongsPage() {
QmlDocument *qml = QmlDocument::create().load("Songs.qml");
if (!qml->hasErrors()) {
songsPage= qml->createRootNode<Page>();
if (songsPage) {
QVariantList sqlData = dataAssist->loadDatabase("quotes.db", "quotes"); 
myDataModel=songsPage->findChild<GroupDataModel*>("songsModel"); 
myDataModel->insertList(sqlData);
myListView = songsPage->findChild<ListView*>("songsList");	
	}
	 Application::instance()->setScene(songsPage); //settings scene to this page works, not when pushed                                                                                                                                                                     }                      

This does not work, and I do not get a populated list unless I set the scene to this page as illustrated in the last line above. It is pushed by deprecated push by string method, I am interested why it does not work unless it is the "first page" whereby the application scene is set to this page and it is the one viewed when opened. 

 

I can elaborate on anything if something is unclear and do not have an in depth knowledge of databasing in this fashion so if it is an obvious problem I apologize for not seeing it earlier. Thanks. 

 

 *EDIT: Sorry about the poor formatting, it pasted terribly.

 

BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: Listview not loading datamodel

I will need to dig deeper in this - is this happening with Beta2? Was it working in Beta1?

 

Martin

 

Developer
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Listview not loading datamodel

Thanks for your reply Martin, I am on vacation at the moment and was unable to respond sooner. I have only attempted this in beta 2, can you confirm that this method is not working? I was hoping there was just something I was missing but it is always possible there is a bug. I just adapted the quotes sample to have the datamodel loaded on a page other than the first page. Using the quotes app code this did not work unless I used the above setScene function. I would be very interested to learn the results of your inquiries and the experience of anyone else who has experienced or overcome this issue.
Developer
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Listview not loading datamodel

[ Edited ]

Have you been able to find the/my error in this implementation of a listview and datamodel? I have been unable to resolve it myself but will continue trying.

BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: Listview not loading datamodel

I've taken some time to investigate, have you tried getting the listview page to display using C++ push() instead of deprecatedPush in QML?

 

Setting the scene should not be required to populate a listview... I would suggest logging an issue for this. Do you currently have a workaround? (setting the scene to the list view page before setting the scene to the main page?)

 

Issue tracker:

https://www.blackberry.com/jira/secure/Dashboard.jspa

 

Martin

Developer
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Listview not loading datamodel

I have not yet tried push but will do that shortly, although I am concerned about this error: http://supportforums.blackberry.com/t5/Cascades-Development/NavigationPane-second-push-freezes-and-c...

 

in which pushing a second time causes it to not work and freeze in some cases. Is this issue rectified? Also, I currently do not have a workaround really as it is inconvenient to set the scene to the page with the listview but I will keep looking at solutions. It works fine if I use an XML datamodel, it is the SQL database datamodel which fails to work, I will  look into launching an issueTracker. Since noone else has reported problems with this I still believe it is something that I am not doing or that needs to be changed when altering something like the quotes app, which is set to the scene to have it instead run on a different page. Thanks again for your help and if you need any more info or code feel free to ask.

 

Dan.

Developer
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Listview not loading datamodel

quick question, how would it be pushed, isn't the tabbedpane the parent? If so, a tabbedpane does not have a push feature. It seems impossible to have a the SQL datamodel load onto a listview of a page which is a tab of a tabbedpane. I would be interested to see if anyone has accomplished this. 

Developer
rock_win
Posts: 136
Registered: ‎02-01-2009
My Device: Not Specified

Re: Listview not loading datamodel

Hi,

 

I was working on this and have got it working on simulator and device.

 

Although not sure how it fits yours current implementation, the key for my implementation was to reuse the save list view refrence on both the pages with interchanging data model.

 

And then as soon as the data model is set, the content would load.

 

Thanks!

BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: Listview not loading datamodel

Hi,

Hmm I was looking into NavigationPane, not TabbedPane…I will experiment a bit more today;
Have you made any progress or more observations?

Martin

Developer
vingilot
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Listview not loading datamodel

I actually changed it last night and was successful. Following the advice of rock_win, I  do not  take the dataModel from the QML as I initially demonstrated but create a dataModel  in the C++ which is accessible to the QML. This implementation worked, it seemed as though it could not load properly if I tried to retrieve the ListView and DataModel, I now just have:

 

myDataModel = new GroupDataModel(QStringList() << "songname");
myDataModel->insertList(sqlData);

 

 

where before I had:

 

myDataModel=songsPage->findChild<GroupDataModel*>("songsModel"); 
myDataModel->insertList(sqlData);
myListView = songsPage->findChild<ListView*>("songsList");

And it is working properly. If you would like to discuss this more or see more of my implementation I can certainly do that, otherwise I will select the thread as closed.