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
New Developer
Posts: 40
Registered: ‎12-14-2013
My Device: Playbook
My Carrier: Orange

Storing links in database

Hi,

 

I want to store the urls in database and then show it in the listview using the data model.

 

Currently this is what i'm doing 

 

main.qml

 

TabbedPane {
Tab {
title: "Links"
Page {
Container {
    ListView {
        dataModel: _links.model
                listItemComponents: [
                        
                   ListItemComponent {
                       type: "item"
                         
             Container {
             layout: StackLayout {
                     orientation: LayoutOrientation.TopToBottom
                                }
                        Container {
                           title: ListItemData.title
                                     
                             }
                        Container { 
                           title: ListItemData.link
                           }
                          }
                        }
                 ]
           }
      }
   }
}

Tab {
Page {
Container {
    Webview {

      onNavigationRequested: {

          _links.mywebLinks(webView.title, webView.url)
          }
      }
  }
}

 

 

 links.cpp

 

void links::mywebLinks(QString str, QUrl url) {

	QVariantMap linksW;

    linksW["title"] = QVariant(str);
    linksW["link"] = QVariant(url);
    m_model->insert(linksW);
}

 as you can see, i'm directly using the links from the main.qml file and displaying it in the list using the data model. But this is for temporary use only. To be able to use the link even after the app restarts, the links need to be stored on any database.

 

Now the problem is, i'm not sure how to use the database to store the link and eventually retrieve it using the datamodel to display in the listview in qml. I went through the offical documentation but still not sure how to go about it.

 

Can anyone help me? Some demo code showing how to store the links in database and eventually display it in the list using the datamodel would higly appreciated. Thanks