Search code examples
blackberry-10blackberry-cascades

Create a json file , write Json data into it and Load the file into JsonDataAccess in bb 10 cascades


I have this method call

QList<QByteArray> SocketBase::readAllSymb(QTcpSocket *socket) {

QList<QByteArray> listAll;
int bytesAvail = waitForInput(socket);

if (bytesAvail > 0) {
    //int symbolCount = 0;
    int cnt = 0;
    bool endOfLine = false;
    bool endOfStream = false;


    while (cnt < bytesAvail && (!endOfLine) && (!endOfStream)) {

         QByteArray ba="";

         ba=socket->readAll();

         listAll.append(ba);

         if(ba.endsWith(']')){
             endOfStream = true;
         }
         ba="";
    }
}

return listAll;

}

now my Question is How to create a Dynamic file programatically and write data in to the file and load it like .... JsonDataAccess jda;

  QVariant list = jda.load(QDir::currentPath() +
                     "/app/native/assets/employees.json");

Solution

  • To save a QMap to a file:

    QFile file("out.txt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
         qWarning() << "Couldn't open file";
         return;
    }
    
    JsonDataAccess jda;
    jda.save(map, &file);