JsonDataAccess

I don't know if it's just me, but for some reason this code

bb::data::JsonDataAccess ja;
QVariant jsonva = ja.loadFromBuffer(info);

not working anymore since I moved to beta 2. What has changed since Beta1-> beta 2?

Thank you

Open the .pro file and add the line:

LIBS +=-lbbdata

Tags: BlackBerry Developers

Similar Questions

  • Cannot use JsonDataAccess to load the json

    I have the Json file

    [
    {"param":"earfree/earfree","value":true},
    {"param":"earfree/smart_mode","value":true},
    {"param":"earfree/vb_ledcolor_index","value":fales},
    {"param":"earfree/vb_ledcolor_value","value":true},
    {"param":"earfree/vb_remote_accept","value":true},
    {"param":"earfree/vb_remote_reject","value":true},
    {"param":"earfree/vb_remote_failed","value":true},
    {"param":"earfree/callend_alert","value":true},
    {"param":"earfree/vb_accept","value":false},
    {"param":"earfree/vb_reject","value":false}
    ]
    

    I have this code

      JsonDataAccess jda; QVariant list = jda.load("app/native/assets/models/defaultsettings.json");
    
     if (jda.hasError()) { DataAccessError error = jda.error(); qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();// return; } else { qDebug() << "JSON loading ok";  JsonDataAccess jda;
        QVariant list = jda.load("app/native/assets/models/defaultsettings.json");
    
        if (jda.hasError())
        {
            DataAccessError error = jda.error();
            qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
        }
        else
        {
            qDebug() << "JSON loading ok";}
    

    ("When I run mode debugging to QVariant list = jda.load("app/native/assets/models/defaultsettings.json ");
    I had this error on the console: ' Python Exception no "QMetaType" symbol in the current environment.:

    And on the table of Variables, the value 'list'

    "Error list: several errors reported." "------cannot run the MI command: - var - create - * error message list of debugger backend: cannot instantiate printer to default visualizer\ cannot create the variable object\ cannot run the MI command: - var - create - * error message list of debugger backend: failed to instantiate printer for default visualizer"

    Please help me.

    Thank you!

    A quick copy paste your JSON in a validator online JSON parser/pointing to typo in one of your 'false' value, you wrote fasle instead.

    https://postimg.org/image/809nbgbot/

  • JsonDataAccess bug?

    I try to analyze it:

    {
        "activities":[
            {
                "activityId":,
            },
           <..>
        ],
        "goals":{
            "activeScore":,
        },
        "summary":{
            "distances":[
                {"activity":"tracker", "distance":},
                {"activity":"loggedActivities", "distance":},
                <..>
            ],
            "elevation":,
            "veryActiveMinutes":
        }
    }
    

    And here is my code:

    void ApiResponse::parse(QByteArray data) {
        JsonDataAccess jda(new QObject);
        QVariant resp = jda.loadFromBuffer(data);
        if (resp.canConvert(QVariant::List)) {
            foreach(const QVariant &var, resp.toList()) {
                qDebug() << var;
            }
        } else if (response != NULL && resp.canConvert(QVariant::Map)) {
            response->parse(resp.toMap());
        }
    }
    

    So I expect to get a card that has 'activities', 'objective' and 'summary', but I get only 'activities '.  I checked this by placing a breakpoint at the beginning of the parse method.

    Is there something that I am missing so he could get the other objects?

    Edit: also after trying to debug even more that I noticed when I opened "resp." I see this:

    The data have 112 'p' tank, well, when I open the QByteArray and copy its values into notepad ++, I see two places that correspond to 112 'p', 84 char and char 558.  This could mean, he stopped the analysis or the other of these two points?  A memory problem?

    OK, I've printed version QString QByteArray, added to a file (results accurate, unmodified) and I always get only 'activities'.

    Edit, actually, when I break point on it, it only shows not her, but if I look at the value after I take for it, its here!  Strange that I can't see when we watch in the display of the Variables.  And I thought that it was not the case is because I had in my QML a label with the text: "active Score:" + activities.activeScore and he turned upward undefined, and he was showing undefined because I have another strong component of activities at the same time, I tried to link a q_object to this label. "  It's working now, thank you!

    See what you get with this:

    {
        "activities":[]
        ,"goals":
            {"activeScore":1000,
            "caloriesOut":2184,
            "distance":8.05,
            "steps":10000}
        ,"summary":
            {"activeScore":1,
                "activityCalories":0,
                "caloriesOut":1618,
                "distances":[
                    {"activity":"total","distance":0}
                    ,{"activity":"tracker","distance":0}
                    ,{"activity":"loggedActivities","distance":0}
                    ,{"activity":"veryActive","distance":0}
                    ,{"activity":"moderatelyActive","distance":0}
                    ,{"activity":"lightlyActive","distance":0}
                    ,{"activity":"sedentaryActive","distance":0}
                ]
                ,"fairlyActiveMinutes":0
                ,"lightlyActiveMinutes":0
                ,"marginalCalories":0
                ,"sedentaryMinutes":945
                ,"steps":0
                ,"veryActiveMinutes":0
            }
    }
    

    Edit: My guess is that its a problem with the activities being empty or the fact that the values are not strings.  Simply by looking at the difference between your example json and mine.

  • JsonDataAccess 3 error code

    Hello

    DOE anyone know why the JsonDataAccess returns the error 3 code?

    2 hours ago, the app worked like a charm, and now it returns error code 3 on JsonDataAccess on all my json (witch is valid json checked on jsonlint.org)

    JsonDataAcces error message:

    "* Line 1, column 1".

    Syntax error: value, object or table provided.

    "

    Someone an idea?

    THX.

    Gr.

    I found the sollution I made a mistake.

    qDebug() < qstring(reply-=""> readAll());<== returned="" the="" json="" value="" like="">

    JsonDataAccess.loadFromBuffer (response-> readAll()); readAll() <== here="" reply-="">is empty, so it returns the error

  • Problem in the use of JSONDATAACCESS for parsing json getting as the server Http response.

    Hey Hi,

    I was tired this solution but get a problem. The problem is when I am trying to build my project it gives an error stating that ' expected ';' before ' ja ' when I declare JsonDataAccess.

    Here is my code snippet:

    JsonDataAccess ja;
    QString response;
    If (response-> error() == QNetworkReply::NoError) {}
    const int available = response-> bytesAvailable();
    If (available > 0) {}
    answer = QString::fromUtf8 (response-> readAll());
    qDebug()< "tag="" name="" is="" ::=""><>
    QVariant jsonva = ja.loadFromBuffer (response);

    }

    even after the addition of the LIBS +=-lbbdata in the .pro file I get no success here.

    Help, please

    Concerning

    Don't forget to:

  • JsonDataAccess error in JSON even report it is valid

    I have a problem with parsing JSON which I get from QNetworkReply. I checked on http://json.parser.online.fr/beta/ if json is valid and it is:

    {
        "status": 0,
        "objects": [{
            "id": "i_53909cc3eeafd",
            "name": "picture1",
            "location": [{
                "x": -5,
                "y": 126
            }, {
                "x": 266,
                "y": 126
            }, {
                "x": 269,
                "y": 396
            }, {
                "x": -5,
                "y": 400
            }]
        }]
    }
    

    I use following code:

    void ApplicationUI::onRequestFinished(QNetworkReply* reply) {
    
        QString response = QString::fromUtf8(reply->readAll());
    
        if(reply){
            if(reply->error() == QNetworkReply::NoError) {
    
                JsonDataAccess jsonDataAccess;
                QVariant list = jsonDataAccess.loadFromBuffer(response);
                if (jsonDataAccess.hasError()) {
                    DataAccessError error = jsonDataAccess.error();
                    qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
                    return;
                }
            } else {
                qDebug() << "Network error!";
            }
        }
    
    reply->deleteLater();
    }
    

    Everyt time I receive reply jsonDataAccess shows me error:

    JSON loading error:  3 :  "* Line 1, Column 1
      Syntax error: value, object or array expected.
    "
    

    The second problem is the fact that I am not able to access the values of this json response. I tried many possibilities and I always get empty results.

    OK, the problem is now resolved. I realized that my QNetworkAccessManager I had after the line:

    request.setRawHeader(QString("Accept-Encoding").toAscii(), QString("gzip,deflate").toAscii());
    

    Who was raping my JSON.

  • JSonDataAccess HowTo strip certain characters

    I always fight if you use regular expressions ;-)

    Maybe someone can give me a hint

    using JSonDataAccess saveToBuffer() I have a very uncomfortable way to get a JSON or a QVariantMap, as well as QVariantList.

    now I'm in a special usecase compact the resulting string of saveToBuffer()

    Here are the rules:

    remove all line breaks

    remove all white space in front and behind {}

    {remove all white space in front of and behind}

    remove all white space in front and behind]

    [remove all white space in front of and behind]

    remove all white space in front and behind:

    remove all white space in front and behind.

    all other areas must remain so:

    {'Name': 'Jane Doe'}

    {'City': 'Boston'}

    becomes:

    {'Name': 'Jane Doe', 'City': 'Boston'}

    Thanks for the tips

    Oh, according to this page (http://www.freshbrewedcodes.com/jimcowart/2013/01/29/what-you-might-not-know-about-json-stringify/) JSON.stringify () produces the compact shape directly. If you can use QML here, you should be able to convert with JSON.stringify (JSON.parse (yourdata)).

  • JsonDataAccess and Insertion of DB

    IAM having the following .json file

    [
        {
            "title" : "Mike",
            "titleArabic" : "Chepesky",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        },
        {
            "title" : "Westlee",
            "titleArabic" : "Barichak",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        },
        {
            "title" : "Ian",
            "titleArabic" : "Dundas",
            "shortDesc":"[email protected]",
            "shortDescArabic":"1-234-567-8910",
    
        }
    ]
    

    I need to parse this json file and insert the data into a table named 'How_To' in DB.

    Here's the code I used to parse json and insert data from DB

    void ApplicationUI::jsonParser()
    {
             JsonDataAccess jda;
            QVariant jsonva = jda.load("app/native/assets/data.json");
            if (jda.hasError())
                {
                    bb::data::DataAccessError error = jda.error();
                    qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
                    return;
                }
            else
            {
                 QVariantList list = jsonva.toList();
                 for (QList::iterator it = list.begin(); it != list.end(); it++)
                  {
                        QVariantMap map = it->toMap();                              qDebug(<
    

    My problem is:

    (1) there is no value available on the map that I created while reiterating the answer jsonDataAccess

    Where Iam wrong please help me

    Hi SumiSadiq,

    The problem is in the format of your .json file. Remove the comma after the value of the last attribute (shortDescArabic) it will do the job. I tried the code by using the sample application stampcollector and the map values were retrieved correctly on the console.

  • JsonDataAccess problem

    Hello

    IAM trying to load a json file ive downloaded. (Download works, checked if the file already exists in my "data / blabla.json")

    But now, when I try to use JsonDataAccess, it returns the following error during the generation

    expected ';' before 'jda' OR 'JsonDataAccess' was not declared in this scope
    

    the only thing I did:

    #include /* ... */void app::parseJson(){    if (json->exists()) {
        JsonDataAccess jda;
        }}
    

    Does anyone have an idea?

    THX

    EDIT

    After you have added

    using namespace bb::data;
    

    It worked!

    Of course

    In your header file to register the slots and the vars

    private slots:   void requestFinished(QNetworkReply *reply);
    
    private:   QNetworkAccessManager *mNetworkAccessManager;   QFile *file;
    

    for example (pseudocode)

    App.h

    #ifndef APP_H_
    #define APP_H_
    //* includes & namespaces here *//class App{public:
        App();    Q_INVOKABLE void init();
    
    private slots:
        void requestFinished(QNetworkReply *reply);
    
    private:
        QNetworkAccessManager *mNetworkAccessManager;
        QFile *json;
    };
    
    #endif /* APP_H_ */
    

    Then in your constructor to create access like this manager network

    mNetworkAccessManager = new QNetworkAccessManager(this);
    

    then add the signals and slots and make sure to check out them after that

    bool result = connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));
    
    Q_ASSERT(result);
    Q_UNUSED(result);
    

    what I did to create the reference here file

    json = new QFile("data/file.json");
    

    Then call the method init to start on demand, I think the Q_INVOKABLE is necessary only when you call the init method of QML

    init();
    
    // init method looks like thisvoid App::init(){QNetworkRequest request = QNetworkRequest();    request.setUrl(QUrl("url to json"));    mNetworkAccessManager->get(request);}
    

    and finally in the SLOT, we used requestFinished(QNetworkReply *reply) so that's how this method resembles

    void App::requestFinished(QNetworkReply *reply){
        qDebug("Request finished");
        qDebug() << reply->error();
        qDebug() << reply->errorString();
        if (reply->error() == QNetworkReply::NoError) {
            qDebug() << "No error";
    
            QByteArray data = reply->readAll();
    
            if (!json->open(QIODevice::ReadWrite)) {
                qDebug() << "Failed to open file";
                return;
            }
    
            json->write(data);
            json->flush();
            json->close();
    
            qDebug() << "JSON file fetched and saved to 'data/file.json'";
    }
    

    I hope this helps.

    Welcome,

    Xtravanta

  • 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

  • Issue of SqlDataAccess

    Hello

    So, as a warning, I'm really out of practice with C++ development, so this could be something simple.

    Yesterday, I downloaded the new NDK (10.0.06) and open my application.  There is some method of API changes that I corrected quickly, but there is a question I have that I can't solve.  In my application, I use a SqlLite DB.  The following is a code snippet:

    SqlDataAccess sqlDataAccess("myDB.db");
    sqlData = sqlDataAccess.execute("select * from myTable").value();
    if (sqlDataAccess.hasError()) {
      DataAccessError err = sqlDataAccess.error();
      qWarning() << "SQL error: type=" << err.errorType() << ": "
        << err.errorMessage();
      return sqlData;
    }
    

    It worked A-OK in 10.0.04 (as in the example of project of quotes), but now, compilation fails with

    "reference to the undefined ' bb::data:qlDataAccess:qlDataAccess (const QString &, QObject *)' '.

    (as well as others).

    My head is particularly

    and

    and using the bb::data namespace.

    My class file is to use the bb::data namespace.

    Any help would be appreciated!

    Thank you

    Dan Slack

    Found the solution - I checked in my code and was getting the same error with the JsonDataAccess object.  And, from there, someone posted a solution to this here.

    TL; DR - add

    LIBS +=-lbbdata

    to your projects ".pro" file (I just added at the bottom).

  • How to create a Json structure programmatically in Qt

    Hi all

    I know to parse a json structure, but not vice versa.

    This is the structure that I need to create.

    {'3': ['Num accounts', '1'], '2': ['Version', '1'], '1': ["OS, BB10", '10.2.1.0'], '4': ['Local', 'en_US']}

    Can someone tell me how do in a standard way.

    Look here

    https://developer.BlackBerry.com/native/reference/Cascades/bb__data__jsondataaccess.html#function-SA...

    QByteArray buffer;
    JsonDataAccess jda;
    jda.saveToBuffer(QVariant(map), &buffer);qDebug() << buffer;
    
  • Json stream composed and ListView

    Hello world

    This seems to be a simple problem with a simple solution, I just can't understand it.

    Loading a simple json in a list view is simple:

    jsonDataAccess = new JsonDataAccess();
    QVariant json = jsonDataAccess->loadFromBuffer(data);
    jsonDataModel->insertList(json.value());
    jsonListView->setDataModel(jsonDataModel);
    

    It works for the flows that are simple, as in the example of many on this site:

    [
        {
            "firstName" : "Mike",
            "lastName" : "Chepesky"
            "employeeNumber" : 01840192
        }
    ]
    

    What about Situations like this:

    {
    
        "error":null,
        "result":"success",
        "count":17,
        "podcasts":[
            {
                "title":"Arts",
                "image_url":"http://cdn.99percentinvisible.org/wp-content/uploads/powerpress/99in visible-logo-1400.jpg",
                "podcasts_url":"/api/v2/podcasts/category/145",
                "category_id":145
            },
            {
                "title":"Business",
                "image_url":"http://newdisruptors.s3.amazona ws.com/images/ND_full_iTunes.jpg",
                "podcasts_url":"/api/v2/podcasts/category/143",
                "category_id":143
            }]
    

    In the case above is not 'just work', I want to fill my ListView with all information under "podcasts", including the title, image_url, etc... But I can't understand how insert only that part of the json is fed into the model of group data.

    How to insert specific parts of the food in the Datamodel?

    See you soon,.

    EI

    I thought about it, the answers were already riddled through the forums. I guess I was looking for a "simple" solution, although it is short, it was not obvious.

    QVariantMap podcasts = jsonList.value();
    QVariantList podcatlist = podcasts.value("podcasts").toList();
    foreach (QVariant category, podcatlist)
    {
        categoryDataModel->insert(category.toMap());
    }
    categoryListView->setDataModel(categoryDataModel);
    
  • ContactService blocking UI thread

    While working with ContactService I noticed thread interface user cascading gets completely blocked even if I use the contacts optimized pick.

    Filtering only contacts that have e-mail and phonenumbers out 1000 contacts, takes about 3 seconds.

    Maybe I'm crazy, but this is not acceptable.

    Here is the code I use:

    void ApplicationUI::fetchContacts()
    {
        QVariantList contactsList;
        ContactService service;
        QList contactPage;
        ContactListFilters options;
        const int maxLimit = 20;
        QSet kindList;
        kindList.insert(AttributeKind::Phone);
        kindList.insert(AttributeKind::Email);
    
        options.setSortBy(SortColumn::LastName, SortOrder::Ascending);
        options.setIncludeGroups(false);
        options.setIncludePhotos(false);
        options.setIncludePostalAddress(false);
        options.setLimit(maxLimit);
        options.setHasAttribute(kindList);
    
        do {
            contactPage = service.contacts(options);
    
            foreach (const Contact &idContact, contactPage) {
                const Contact contact = service.contactDetails(idContact.id());
                const QList phoneNumbers = contact.phoneNumbers();
                const QList emails = contact.emails();
                QVariantMap entry;
    
                if (!phoneNumbers.isEmpty() && !emails.isEmpty()) {
                    entry["name"] = contact.displayName();
                }
    
                if (!phoneNumbers.isEmpty()) {
                    QVariantList phonNoList;
                    for(int i=0; ifetchContactsListCompleted(contactsList);
    
        QString result;
        bb::data::JsonDataAccess jda; //this line works only on BB
        jda.saveToBuffer(QVariant(contactsList), &result);
        if (!jda.hasError()) {
            emit this->fetchContactsCompleted(result.simplified().toUtf8());
        }
    }
    

    Now, as I see it, I have 2 options.

    We must implement my own multithreading and make async.

    Edit the event when I extract contacts.

    Before going with my own multithreading, is that what I'm doing wrong and the code still optimize?

    Here's how I did and so far very notes with results.

    In the header of your class says:

    private:
        QVariantList doContacts();
        QFutureWatcher futureWatcher;
    
    private Q_SLOTS:
        void onDoContactsFinished();
    

    In your class constructor, establish a connection:

        bool connectContacts = connect(&futureWatcher, SIGNAL(finished()), this, SLOT(onDoContactsFinished()));
        Q_UNUSED(connectContacts);
        Q_ASSERT(connectContacts);
    

    Basically, existing function has been divided into 2 rewritten and additional functions. Be careful how the member function is called in QtConcurrent and where exactly has QFuture together. Questions of command line. It now looks like this:

    void ApplicationUI::fetchContacts()
    {
        QFuture future = QtConcurrent::run(this, &ApplicationUI::doContacts);
        futureWatcher.setFuture(future);
    }
    
    QVariantList ApplicationUI::doContacts()
    {
        QVariantList contactsList;
        ContactService service;
        QList contactPage;
        ContactListFilters options;
        const int maxLimit = 20;
        QSet kindList;
        kindList.insert(AttributeKind::Phone);
        kindList.insert(AttributeKind::Email);
    
        options.setSortBy(SortColumn::LastName, SortOrder::Ascending);
        options.setIncludeGroups(false);
        options.setIncludePhotos(false);
        options.setIncludePostalAddress(false);
        options.setLimit(maxLimit);
        options.setHasAttribute(kindList);
    
        do {
            contactPage = service.contacts(options);
    
            foreach (const Contact &idContact, contactPage) {
                const Contact contact = service.contactDetails(idContact.id());
                const QList phoneNumbers = contact.phoneNumbers();
                const QList emails = contact.emails();
                QVariantMap entry;
    
                if (!phoneNumbers.isEmpty() && !emails.isEmpty()) {
                    entry["name"] = contact.displayName();
                }
    
                if (!phoneNumbers.isEmpty()) {
                    QVariantList phonNoList;
                    for(int i=0; ifetchContactsListCompleted(contactsList);
    
        QString result;
        bb::data::JsonDataAccess jda;
        jda.saveToBuffer(QVariant(contactsList), &result);
        if (!jda.hasError()) {
            emit this->fetchContactsCompleted(result.simplified().toUtf8());
        }
    }
    

    I am open to any suggestions or improvements.

  • Problem, the signals and Slots

    Hi, as I posted in one of my other posts I have following problem with signals and messages and would be nice if someone could clarify anything that I don't seem to be able to find what the problem of the outputs.

    I have the code:

    void MYNetworkClass::requestFinished(QNetworkReply* reply)
    {
    
          // Check the network reply for errors
          if (reply->error() == QNetworkReply::NoError)
          {
             // read response
             const QByteArray response(reply->readAll());
             qDebug() <<"Response: "<< response;
    
             JsonDataAccess jda;
             QVariantMap results = jda.loadFromBuffer(response).toMap();
    
             QVariantMap data = results.value("SomeData").toMap();
    
             emit signalSuccess(data); // I reach here .... 
    
    // however actually when I click "Step Over" in debug mode, and try to exit the function// afterwards I get such "error" saying: No source available for "QMetaObject::activate() at  0xb9668da7" - highlighted in red.
    
         }
         else
         {
             qDebug() << "\n Problem with the network";
             qDebug() << "\n" << reply->errorString();
         }
    

    In MyNetwork class I also added the definition of signal in the header file:

    signals:
    
        void signalSuccess(QVariantMap result);
    

    Now also when someone calls an object MyNetworkClass method which calls requestFinished,.

    I want to catch the signal which is emitted by the requestFinished - as shown above.

         MyNetworkClass *network = new MyNetworkClass();
    
        QMap params;
        params.insert("username", userEmail);
    
        bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
    
            Q_ASSERT(res);
        Q_UNUSED(res);
            network->makePostRequest("Login");
    

    My problem is that the SomeSlotForSignal slot never is called... (even if the signal is issued constitute requestFinished method and as I stated SomeSlotForSignal as a crack in the header file...) What can be problem? Any help? Thank you.

    I guess I solved the problem.

    The code I presented previously registered function

    F of a class B:

     void B::f()
    {
    MyNetworkClass *network = new MyNetworkClass();
    
        QMap params;
        params.insert("username", userEmail);
    
        bool res = QObject::connect(network, SIGNAL(signalSuccess(QVariantMap)), this, SLOT(SomeSlotForSignal(QVariantMap)));
    
            Q_ASSERT(res);
        Q_UNUSED(res);
    
    network->makePostRequest("Login");
    }
    

    Then the function f is called to:

        B object;
        object.f();
    
    The problem was I think that when the server responded "object" was destroyed from the stack. When I replaced the above code, with 
    
         B* object = new B();
        object->f();
    
    I think it works now......
    

Maybe you are looking for