我有这个方法调用
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;
}
现在我的问题是如何以编程方式创建动态文件并将数据写入文件并加载它... JsonDataAccess jda;
QVariant list = jda.load(QDir::currentPath() +
"/app/native/assets/employees.json");
答案 0 :(得分:2)
将QMap保存到文件:
QFile file("out.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Couldn't open file";
return;
}
JsonDataAccess jda;
jda.save(map, &file);