QVariantList in ArrayDataModel

Hello

I have a little problem with getting the information of my ArrayDataModel in C++.

My ArrayDataModel contains items that are QVariantMaps, each of which contains several QStrings.

Here's how I fill this ArrayDataModel:

QVariantMap map;map.insert("name", name);
map.insert("path", path);
map.insert("completePath", FileToOpen);

model->append(map)

Not in another function, I want to go back 3. element in the QVariantMap, means the QString FileToOpen.

How can I do?

That's what I got so far:

for (int i = 0; i < model->size(); i++) {
    model->value(i);
}

With this, I get that:

QVariant(QVariantMap, QMap(("completePath", QVariant(QString, "completePath") ) ( "name" ,  QVariant(QString, "filepath") ) ( "path" ,  QVariant(QString, "filepath") ) )  )

But how do I get as a string of this QVariantMap?

I think it should be pretty easy, but I'm stuck. Can someone help me out here?

In the ArrayDataModel docs (https://developer.blackberry.com/native/reference/cascades/bb__cascades__arraydatamodel.html#functio... I found that with the 'data' function, I get the question but I don't know how to use it here.

Get you with card-> value ().

i.e. s QVariant = map-> value("name")

http://Qt-project.org/doc/Qt-4.8/QMAP.HTML#value

Tags: BlackBerry Developers

Similar Questions

  • arraydatamodel with QvariantList

    I have an arraydatamodel added to a list.

    I want to fill the ArrayDataModel of a database data source

    My datamodel returns a QVariantList which seems that it is not supported by the arraydatamodel.

    How can I solve this problem in QML and add objects contained in the QVariantList?

    PS: I don't want to use the GroupedDataModel

    attachedObjects:]
    DataSource {}
    ID: modelsDataSource
    Source: "sql/lists.db.
    query: "" SELECT * FROM cars ORDER BY id ".
    property int loadCounter: 0
                                        
    onDataLoaded: {}
    If (data.length > 0) {}

    arrayModel.insert (data);<------------ here="" is="" the="" problem,data="" is="" a ="">
    ;
    }
    }
    }

    Try:

    arrayModel.clear();
    for(var i = 0; i < data.length; ++i)
    {
      arrayModel.append(data[i]);
    }
    
  • How to manage updates of data in ArrayDataModel

    Hello

    I load some data from a JSON file in a QVariantList which is then added to an ArrayDataModel that allows to display the data in a ListView. It all works very well. Now, I want to update certain values of a ListViewItem and want to propagate these changes to the ArrayDataModel-> QVariantList-> JSON file. How I would handle this? Should I update the DataModel, ListView or even the QVariantList? Loading and display of data in a ListView are very well documented, but I can't find information on reverse litle?

    Any help will be greatly appreciated!

    You can access the dataModel of ListView items so it is possible to directly manipulate.

    Outside the ListView join dataModel signals such as

    void   itemAdded (QVariantList indexPath)
    void    itemUpdated (QVariantList indexPath)
    void    itemRemoved (QVariantList indexPath)
    void    itemsChanged (bb::cascades::DataModelChangeType::Type eChangeType=bb::cascades::DataModelChangeType::Init, QSharedPointer< bb::cascades::DataModel::IndexMapper > indexMapper=QSharedPointer< bb::cascades::DataModel::IndexMapper >(0))
    

    You'll probably have to subscribe to each of them as you know what changes you make to the dataModel. For example, if you only update the elements subscribe to itemUpdated etc..

    In Manager signals, extract the dataModel changes and save them to the disc.

    PS Don't forget to subscribe to the changes that the dataModel is initially populated.

  • solution: bps netstatus_interface_list_t as QVariantList

    I was looking for an easy way to know the name of the interface for WIFI, cell PHONE...

    These names are different for Z10, Z30, Q10,... you can't find names

    First aid, I found was Cascades Sample App "MyDevice".

    Congratulations to Martin Woolley @mdwrim providing this app to wander on Github

    Now I could get the names of WIFI connections, but lacked a way to get the names for cell PHONES

    discussed with @mdwrim on twitter and got to come an interface more names for cell PHONES, but this could be broken easy to new devices.

    next congratulations to @dkonigs who joined the discussion on twitter mentioning Netstatus API to inspect the Interface Types

    OK - I wanted to use the netstatus and discovered that I have a loop through a list of interfaces netstatus and tried this code.

    thought it would be easy because I already used Netstatus events to know if the user is on WIFI, cell PHONE etc.

    But I have to give up - as a former Developer Java and C++ now / Qt developer such things bps C does not for me.

    next Bravo to strobejb help with the code in this thread here. Based on his code I solved it and now it's easy to know all the Netstatus Interfaces.

    Here is a method that you give bps bps netstatus_interface_list_t as QVariantList, so you can use for data models, storing as JSON or almost.

    QVariantList YourClass::netStatusInterfaceList() {
        QVariantList interfaceList;
        netstatus_interface_list_t iflist;
        netstatus_get_interfaces(&iflist);
    
        for (int i = 0; i < iflist.num_interfaces; i++) {
            netstatus_interface_details_t *details = 0;
            netstatus_get_interface_details(iflist.interfaces[i], &details);
            if (details) {
                QVariantMap interfaceDetailsMap;
                const char *name = netstatus_interface_get_name(details);
                qDebug() << "DETAILS FOR Interface: " << name;
                interfaceDetailsMap.insert("name", name);
                netstatus_interface_type_t type = netstatus_interface_get_type(
                        details);
                bool connected = netstatus_interface_is_connected(details);
                interfaceDetailsMap.insert("connected", connected);
                bool up = netstatus_interface_is_up(details);
                interfaceDetailsMap.insert("up", up);
                interfaceDetailsMap.insert("hasType", type ? "true" : "false");
                if (type) {
                    interfaceDetailsMap.insert("type", type);
                    switch (type) {
                    case NETSTATUS_INTERFACE_TYPE_WIRED:
                        interfaceDetailsMap.insert("typeName", "WIRED");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_WIFI:
                        interfaceDetailsMap.insert("typeName", "WIFI");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_VPN:
                        interfaceDetailsMap.insert("typeName", "VPN");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_BB:
                        interfaceDetailsMap.insert("typeName", "BB");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_UNKNOWN:
                        interfaceDetailsMap.insert("typeName", "UNKNOWN");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_USB:;
                        interfaceDetailsMap.insert("typeName", "USB");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_BLUETOOTH_DUN:
                        interfaceDetailsMap.insert("typeName", "BLUETOOTH_DUN");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_CELLULAR:
                        interfaceDetailsMap.insert("typeName", "CELLULAR");
                        break;
                    case NETSTATUS_INTERFACE_TYPE_P2P:
                        interfaceDetailsMap.insert("typeName", "P2P");
                        break;
                    default:
                        interfaceDetailsMap.insert("typeName", "????");
                        break;
                    }
                }
                if (connected) {
                    // enumerate the ip addresses for this interface
                    int numip = netstatus_interface_get_num_ip_addresses(details);
                    QVariantList ipAddressList;
                    for (int j = 0; j < numip; j++) {
                        QVariantMap ipAddressMap;
                        const char *ip = netstatus_interface_get_ip_address(details,
                                j);
                        const char *nm = netstatus_interface_get_ip_address_netmask(
                                details, j);
                        ipAddressMap.insert("ipAddress", ip);
                        ipAddressMap.insert("netmask", nm);
                        ipAddressList.append(ipAddressMap);
                    }
                    interfaceDetailsMap.insert("ipAddresses", ipAddressList);
                    // enumerate gateways for this interface
                    int numgw = netstatus_interface_get_num_ip_gateways(details);
                    QVariantList ipGatewayList;
                    for (int j = 0; j < numgw; j++) {
                        QVariantMap ipGatewayMap;
                        const char *ip = netstatus_interface_get_ip_gateway(details,
                                j);
                        ipGatewayMap.insert("gatewayIp",ip);
                        ipGatewayList.append(ipGatewayMap);
                    }
                    interfaceDetailsMap.insert("ipGateways",ipGatewayList);
                }
                interfaceList.append(interfaceDetailsMap);
            } // end if details
              // FREE Memory
            netstatus_free_interface_details(&details);
        }
        // FREE Memory
        netstatus_free_interfaces(&iflist);
        qDebug() << "List of Netstatus Interfaces: " << interfaceList.size();
        return interfaceList;
    }
    

    Thanks again to all the forum here and twitter. It's really nice to work with this great community

    XXXX

    and here is what you will get if the QVariantList was saved from the JsonDataAccess on a Z30:

    [
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "pflog0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "lo0",
          "up" : true
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "rndis0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "ecm0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "bb0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "ppp0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "pan0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "nap0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm4",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm3",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm2",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : true,
          "hasType" : "false",
          "ipAddresses" : [
             {
                "ipAddress" : "10.21.34.184",
                "netmask" : "255.255.255.252"
             },
             {
                "ipAddress" : "fe80::4242:24ff:4242:94d7%msm1",
                "netmask" : "ffff:ffff:ffff:ffff::"
             }
          ],
          "ipGateways" : [
             {
                "gatewayIp" : "10.21.34.184"
             }
          ],
          "name" : "msm1",
          "up" : true
       },
       {
          "connected" : true,
          "hasType" : "true",
          "ipAddresses" : [
             {
                "ipAddress" : "10.51.149.71",
                "netmask" : "255.255.255.240"
             },
             {
                "ipAddress" : "fe80::4242:24ff:4242:94d7%msm0",
                "netmask" : "ffff:ffff:ffff:ffff::"
             }
          ],
          "ipGateways" : [
             {
                "gatewayIp" : "10.51.149.71"
             }
          ],
          "name" : "msm0",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : true
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "bcm1",
          "type" : 2,
          "typeName" : "WIFI",
          "up" : false
       },
       {
          "connected" : true,
          "hasType" : "true",
          "ipAddresses" : [
             {
                "ipAddress" : "192.168.42.42",
                "netmask" : "255.255.255.0"
             },
             {
                "ipAddress" : "fe80::4242:24ff:4242:94d7%bcm0",
                "netmask" : "ffff:ffff:ffff:ffff::"
             }
          ],
          "ipGateways" : [
             {
                "gatewayIp" : "192.168.42.1"
             }
          ],
          "name" : "bcm0",
          "type" : 2,
          "typeName" : "WIFI",
          "up" : true
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "smsc0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "asix0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "vlan0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "vpn0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "openvpn0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "ipsec1",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "ipsec0",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "false",
          "name" : "lo2",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm5",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm6",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : false,
          "hasType" : "true",
          "name" : "msm7",
          "type" : 7,
          "typeName" : "CELLULAR",
          "up" : false
       },
       {
          "connected" : true,
          "hasType" : "true",
          "ipAddresses" : [
             {
                "ipAddress" : "fd38:4242:4242:67b5:dacc:4242:f17e:6af7%59",
                "netmask" : "ff00::"
             },
             {
                "ipAddress" : "fe80::4242:24ff:4242:94d7%bptp0",
                "netmask" : "ffff:ffff:ffff:ffff::"
             }
          ],
          "ipGateways" : [],
          "name" : "bptp0",
          "type" : 8,
          "typeName" : "P2P",
          "up" : true
       }
    ]
    

    the same linking Z10, Q10,... will report the names of different interfaces.

    Martin Woolley also updates the sample MyDevice for use netstatus interface list with QNetworkInterface

  • Unknown ArrayDataModel

    Hi, I'm new to waterfalls and native development and problems of development.

    I wanted to use ArrayDataModel in my class but the compiler know nothing about ArrayDataModel:

    #include

    ..

    private:

    ArrayDataModel * model;

    Compiler:

    CQS-Vgcc_ntox86 - c -Wc, - inclure-Wc,o-g/.obj/ListTest - Wno-psabi - lang-c ++ - fstack-protecteur-strong - g - Wno-psabi-mur -W-D_REENTRANT-DQT_NO_IMPORT_QT47_QML-DQ_OS_BLACKBERRY-DQT_DECLARATIVE_DEBUG-DQT_DECLARATIVE_LIB-DQT_CORE_LIB-DQT_SHARED-je/Applications/bbndk/target_10_0_9_1673/qnx6/usr/share/qt4/mkspecs/blackberry-x86-CQS - j'ai... /.. / ListTest-I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore - I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative - I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4 - I... / SRC-Io-g/.moc-I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include - I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/freetype2 - i. o o-g/.obj/ListTest.o... /SRC/ListTest.cpp in file included from... /SRC/ListTest.cpp:8:0 :... /SRC/Model.HPP:21:2: error: 'ArrayDataModel' does not designate a type

    .. /SRC/model.hpp:29:2: error: 'ArrayDataModel' does not designate a type

    Can someone point me to the solution of the problem please?

    Try the following steps:

    (1) remove #include .h file

    (2) in the .h file before - declare the class as follows:

    namespace bb
    {
      namespace cascades
      {
        class ArrayDataModel;
      }
    }
    

    3)
    Use full names in the header files:

    private:
      bb::cascades::ArrayDataModel *model;
    

    (4) in the C++ file adds:

    #include

    using namespace bb::cascades;

  • QML QVariantList QString Converter?

    Hey all

    I'm relatively new to programming of BB. I have some experience in Android and Windows Phone, but I think that BB10 will kick a lof of * beep *!

    I did a bit of programming for my application and I use a Web service to download the json from the server data. Now, I have programmed a view master / detail with qml, when clicking on an item in the list, I get the details of this item.

    But the article also has QVariantLists because it is a data table. For example, in my json file, I have the language of property: ['Dutch', 'English', 'French'].

    Now, I want to show these multiple languages in my detailpage. Is it possible to write a converter or something like that? Or should I do the treatment before you add data to my datamodel?

    Thanks in advance!

    QVariant-s work just like the javascript in QML tables.
    If you know how to access this QML QVariantList, you can also iterate through it the addition of all the members of a chain.

    var s = "";
    for (var i = 0; i < myList.length; i++) {
     console.log(myList[i]);
    
     if (i != 0)
       s += ", ";
     s += myList[i];
    }
    
  • Fill out the strings of QSettings to ArrayDataModel

    Hello

    I want to read several QSettings strings and then fill in an ArrayDataModel.

    So with this code, I've saved several channels in QSettings:

    void ApplicationUI::saveDataInQSettings(QList filepath) {    QSettings settings;
        settings.beginWriteArray("filepaths");
        for (int i = 0; i < filepath.size(); ++i) {
            settings.setArrayIndex(i);
            settings.setValue("filepath", filepath.at(i));
        }
        settings.endArray();
    }
    

    Now, I want to recover the QSettings channels as follows. I have a C++ function that fills the QSettings strings in a QList:

    QList ApplicationUI::fillQSettingsInQList() {
        QList filepaths;
    
        QSettings settings;
        int size = settings.beginReadArray("filepaths");
        for (int i = 0; i < size; ++i) {
            settings.setArrayIndex(i);
            QString filepath;
            filepath = settings.value("filepath").toString();
            filepaths.append(filepath);
        }
        settings.endArray();
        return filepaths;
    }
    

    In my main.qml, I have a NavigationPane containing a container in which the ArrayDataModel is displayed.

    I put the fillQSettingsInQList () - method in onCreationCompleted then I have the TI in QML when the application is open:

    [...]NavigationPane {
        id: navigationPane
    
        onCreationCompleted: {
            Qt.app = app;
    
            var filepaths = app.fillQSettingsInQList();
        }
    

    But how can I now fill this strings in the ArrayDataModel?

    Thanks for the replies. I have not used the track with a list of the QStrings. It is now much simpler.

    I saved the ArrayDataModel strings in the QSettings in this way. First of all, I saved the channels how I'll put in the QSettings and different channels:

    void ApplicationUI::saveDataModelInQSettings(bb::cascades::ArrayDataModel* model) {
        QSettings settings;
        settings.setValue("size", model->size());
        for (int i = 0; i < model->size(); i++) {
            QVariantMap map = model->value(i).toMap();
            settings.setValue("string_" + QString::number(i), map.value("string"));
        }
    }
    

    And completely action to get the information back to the ArrayDataModel of the QSettings:

    void ApplicationUI::fillQSettingsInDataModel(bb::cascades::ArrayDataModel* model) {
        QSettings settings;
        int size = settings.value("size", 0).toInt();
        for (int i = 0; i < size; i++) {
            QString filepath = settings.value("string_" + QString::number(i), "String not found").toString();
            model->append(filepath);
        }
    }
    
  • Problem getting QVariantList

    I use under coding in my application, but it does not return even in the consol too. If I remove

    If (text [i] .length () > 100)
    continue;

    then back to work properly and if I add consol.log (text [i] .length ()) and then not too much work back the two for another production and in the consol qml

    But I want to delete line which has more that 100 length what mistake I do please help me

    ApplicationUI.cpp

    QVariantList Content1.

    issue of textFileRead (content1);

    Main.QML

    onCreationCompleted: {}
    _APP.textFileRead.connect (onTextFileRead)
    }
    function onTextFileRead (content1) {}
    var text = content1;
    for (var i in the text) {}
    If (text [i] .length () > 100)
    continue;
    mytextarea. Text = mytextarea.text + text [i]
    }

    in JavaScript, you must use .length and not. length()

  • View the QVariantList given on the label?

    Hi Experts,

    I've stored some constant string in QVariantList in C++ file. And I want to print all the stored string in QVariantList on QML label.

    Please suggest me how do.

    Thank you

    the first step is to present the data to the qml. This should cover you there:
    https://developer.BlackBerry.com/native/documentation/Cascades/dev/integrating_cpp_qml/

    qml, you can use the qvariantlist as an array. for example:

    var data = _app.getData();
    for (var i = 0; i < data .length; i ++) {    var label = labelDefinition.createObject();    label.text = data[i].value    labelContainer.add(label)}
    
  • QVariantList gives QString int not

    Hey there

    You have a problem with my QVariantList.

    When I do

    QSettings settings(author, appName); 
    
    if(settings.value("days").isNull()) {
        QVariantList list;
        for(int i = 1; i < 6; i++)
            list.append(i);
        settings.setValue("days", list);
    }
    qDebug() << "initialize: "<< settings.value("days").toList();
    

    He said: initialize: (QVariant (QString, '1'), QVariant (QString, '2'),...)

    But I do of the economies of the int, am I right?

    I need to record the first 5 days to a week.

    The user can select them in a dialog box. The first 5 days are the default.

    When today is in those selected, my headless service did something

    Are you sure?

    By

    if( settings.value("days").toList().contains(
    QDate::currentDate().dayOfWeek() )
      )
    

    I check, if today is one of the days of qsettings.

    Before I changed some of my Code it worked that way.

    Wired-. -.

    I solved it by using QString::number(QDate::currentDate().dayOfWeek())

    I personally would say that it is a workaround

    but in any case, thank you

  • Modification of the ArrayDataModel starting from C++

    Hi, I have a ListView and an ArrayDataModel which is created/initialized in QML. I want to change(add, delete, etc.) the ArrayDataModel c ++.

    How do I get there? Anyone kind enough to provide a code example? Thank you..

    Container {
                id: mainContainer
                ListView {
                    id: listView
                    layout: StackListLayout {}
    
                    dataModel: ArrayDataModel {
                        id: listArrayDataModel
                    }
                   .........
                }
     }
    

    Hello

    There are two different approaches to C++:

    (1) dataModel looking at C++:
    Get a pointer to ListView using findChild. Get its data model using the dataModel() function. Mount this dataModel to store in a variable member ArrayDataModel * then use its methods to add items.

    (2) pass the C++ of QML class model:
    Declare Q_INVOKABLE function in C++ which takes QObject * dataModel as its argument. Export an instance of the class where the function is declared to QML. In QML in onCreationComplete call this function and pass listView.dataModel. In the implementation of the function using qobject_cast(arg) to mount the argument of the ArrayDataModel, verify that the casting was successful and then store the result in a member variable.

    If you need assistance implementation of Scripture above please approach you have chosen, and I will explain more about it.

  • How to extract the value of QVariantlist

    Hello

    I was trying to understand quoteapp example to implement the sqldata in my application. In this example, they are passing all qvariantlist in groupdatamodel and use it in listview. But I don't want to use listview and want to access the value of a particular column in a table on a page. Anyone can guide me please how?

    I'll try to explain what I did to understand how it works. If you have QVarint or QVariantList, right? So now, print it in console with qDebug().

    You will see something like this.

    QVariant(QVariantMap, QMap(("StationButton", QVariant(QString, "") ) ( "StationButtonSelected" ,  QVariant(QString, "") ) ( "StationIcon" ,  QVariant(QString, "0332.jpg") ) ( "StationName" ,  QVariant(QString, "JD Inside") ) ( "StationStreamURL" ,  QVariant(QVariantMap, QMap((".data", QVariant(QString, "http://www.panel-streaming.com/tunein.php/jdinside/playlist.pls") ) ( "type" ,  QVariant(QString, "pls") ) )  ) ) ( "StationURL" ,  QVariant(QString, "http://www.jdinside.com/") ) )  )
    

    So now if I would get Station stream URL type I need to do the following

    QString currType = data.valueQVariantMap>.value("__StationStreamURL__").value ()QVariantMap> ()QString.value("t__ype__").value > ();

    As you can see the first structure is QVariantMap, so we use data.velue() to get it. Then is StationStreamUrl, as QVariantMap and we can get type and convert it to QString. It's something like cabbage, where you need to remove all the layers.

    It will be useful. If not give me what structure you have and I'll try to help you.

    Thank you.

  • How to get items of the multi ArrayDataModel element

    Hello

    When I add items to an ArrayDataModel like that

    // Main.qmlvar data = {"name": filename, "path": filepath}theDataModel.append(data);
    

    How can I get items once again? When I fill out a single item of the data model I can use the value() method

    theDataModel.value(i)
    

    This gives the value added to the i - th position. But now I have items at each position in the data model. How can I get each item? When I use again theDataModel.value (i) I get '[object Object]' as output.

    Your output [object Object] is ok as is JSON object. To access name or path you need this

    theDataModel.value(i).name //print name value
    theDataModel.value(i).path //print path value
    

    Use the method of data instead of the value of your

    https://developer.BlackBerry.com/native/reference/Cascades/bb__cascades__arraydatamodel.html#functio...

  • Crosses QVariantList

    Hello

    I have some JSON data that I import into a QVariantList and using the code below

    I'm going through this list and print elements. But I have two questions:

       JsonDataAccess jda;
       QString path;
       path = QDir::currentPath() +
             "/app/native/assets/employees.json";
       QVariant list = jda.load(path);
    
       QVariantList temp = list.value();
       for (int i = 0; i < temp.size(); ++i) {
           QString gStr = temp[i].toString();
           qDebug()<<"String Value: "<
    

    1. how to use qDebug correctly in Momentics IDE? OS: Mac OS X; nothing is printed, even if I remove the Watcm variable in this line

    2 - is a way to cross the QVariantList and printed content of its elements?

    PS that the temp is initialized correctly, I managed to fill a ListView to use it later.

    Hello

    1. Please check the "Known Limitations" section in the SDK release notes software, it contains information about the configuration of the newspapers:

    https://developer.BlackBerry.com/Cascades/download/releasenotes/

    2. the code is correct. Another way to browse:

    foreach (QVariant v, temp)
    {
      qDebug() << "String Value: " << v.toString() << "\n";
    }
    

    You can also add the new line to serve the line otherwise last exit may be lost on the crash of the application.

    Foreach also makes a copy of the list before to iterate. QT performs lazy copy (copy-on-write) data, so it is not very expensive and you can edit safely from the container during the iteration.

  • Difficulty to remove the element of ArrayDataModel in DeleteActionItem

    Hello

    I have a ListView that is filled with an ArrayDataModel. When I add data to the ArrayDataModel, it works very well. But when I want to delete a data model element in a DeleteAction I get the following error:

    asset:///Main.qml:112: ReferenceError: Can't find variable: theDataModel
    

    Here is my code:

    import bb.cascades 1.2
    import bb.cascades.pickers 1.0
    import bb.data 1.0
    
    import myApplicationData 1.0
    
    NavigationPane {
        id: navigationPane
    
        onCreationCompleted: Qt.app = app
    
        Page {
    
            content: Container {
    
                ListView {
                    id: listview
                    objectName: "listview"
    
                    dataModel: ArrayDataModel {
                        id: theDataModel
    
                        property bool empty: true
    
                        onItemAdded: empty = isEmpty()
                        onItemRemoved: empty = isEmpty()
                        onItemUpdated: empty = isEmpty()
                        onItemsChanged: empty = isEmpty()
                    }
    
                    // Use a ListItemComponent to determine which property in the
                    // data model is displayed for each list item
                    listItemComponents: [
                        ListItemComponent {
    
                            StandardListItem {
                                // Display the value of an item's title property
                                // in the list
    
                        id: component
    
                                title: ListItemData.name
                                description: ListItemData.path
                                imageSource: "asset:///images/icon.png"
    
                                contextActions: [
                                    // Add a set of four actions to the context menu for
                                    // a list item
                                    ActionSet {
                                        title: "Protocol"
    
                                        DeleteActionItem {
                                            onTriggered: {
                                                component.ListItem.view.dataModel.itemRemoved(component.ListItem.indexPath)
                                                theDataModel.removeAt(component.ListItem.indexPath) <---------------- Here I want to remove the data from theDataModel again but I get the error message: "asset:///Main.qml:112: ReferenceError: Can't find variable: theDataModel"
                                                app.ShowToast("Protokoll wurde gelöscht")
                                                app.ShowToastWithoutButton("Protokoll gelöscht")
                                            }
                                        }
                                    } // end of ActionSet
                                ]
    
                                textFormat: TextFormat.Auto
                                status: ""
                                imageSpaceReserved: true
    
                            }
                        }
                    ]
            } // end of Container
    
            actions: [
                ActionItem {
                    title: "Open"
                    imageSource: "asset:///icons/ic_open.png"
                    ActionBar.placement: ActionBarPlacement.OnBar
    
                    onTriggered: {
                        filePicker.open()
                    }
                }
            ]
    
            attachedObjects: [
                FilePicker {
                    id: filePicker
    
                    property string selectedFile
    
                    mode: FilePickerMode.Picker
    
                    type: FileType.Other
                    title: "Open document..."
                    viewMode: FilePickerViewMode.Default
                    sortBy: FilePickerSortFlag.Default
                    defaultType: FileType.Other
                    onFileSelected: {
    
                        selectedFile = selectedFiles[0];
    
                       *select file and fill it to data model *                    var data = {                                "name": name,                                "path": path,                            }                   theDataModel.append(data);  <-------------- here I append the data to theDataModel
                    }
                }
            ]
    
        }
    }
    

    It's the wrong way to access the data model? or how can I remove an item from this data model, when I remove it from the list?

    Try,

    component "". ListItem.view.dataModel.removeAt

Maybe you are looking for