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
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
Accepted Solution

Convert int value from sql to QString without using C++

Hi, I am having some trouble passing an integer value into my list. I am relying entirely on QML and would rather not touch C++ as they tend to create more problems for me sometimes. :smileyfrustrated:

 

I need to load data such as: Int ID, string Otherdata into my GroupDataModel.

 

Problem is:

1) I use the ID as a sorting key

AND

2) I want to display it on my List as well. 

 

I found another solution that calls for the values to be stored as "001, 002, 003" etc. but as I mentioned, I would like to display the information and this is not viable. 

 

I am wondering if I can perhaps use javascript to convert such string? I tried looking for some Qt solutions btu they are all highly reliant on C++ and I do not wish to touch that. 

 

I tried:

 function convertInt (data){return QString(%1).arg(ListItemData.CategoryID || "")}

 But it doesn't seem to work at all...

 

I have also tried ListItemData.CategoryID.toString() but it doesn't work as well... 

 

Can someone please help? Thanks!

 

Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Convert int value from sql to QString without using C++

You shouldn't have to convert it at all, what control are you trying to use it in?

 

Just

 

  text:ListItemData.CategoryID

 

should work.


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30

Re: Convert int value from sql to QString without using C++

Yes, but it is showing up as 'undefined'. Here is my list code;

 

ListView {
                dataModel: GroupDataModel {id: dataModelnew
                    sortingKeys: ["CategoryID", "InvItemID"]
                    grouping: ItemGrouping.ByFullValue
                }
                function itemType(data, indexPath){
                return (indexPath.length == 1? "header" : "item")}
                listItemComponents: [
                    ListItemComponent {
                        type: "header"
                        Header {
                            title: "Category " + ListItemData.CategoryID
                        }
                    },
                    ListItemComponent {
                        type: "item"
                        CustomListItem {
                            dividerVisible: false
                            Container {
                                background: Color.White
                                clipContentToBounds: false
                                Label {text: ListItemData.InvItemName}
                            }
                        }
                    }
                
                ]
            
            }

 I am just wondering if there might be anything to do with the indexPath? The thing is I am using an sql database and I am not entirely sure how the data is mapped out.

Developer
unbreakable
Posts: 74
Registered: ‎12-17-2009
My Device: Z30

Re: Convert int value from sql to QString without using C++

After hours of trial and error, I've finally managed to get the CategoryID to show.

Instead of referring to it as ListItemData.CategoryID, I just used: ListItemData under the header ListItemComponent.

I have also removed the function itemType as it don't seem necessary here atm.

Apparently it is kind of 'automatic' by putting in the the CategoryID in the sortingKeys and grouping.