I also found this very tricky, and remember it took a long while to work out. Eventually in desperation I wrote this handy function:
#include <QDebug>
#include <QDir>
#include <QList>
#include <QUrl>
#include <sstream>
using namespace bb::data;
using namespace std;
void listContents(QDir &src, int depth=0) {
// You app's dirs can be symlinked into libraries, so the depth can go very deep.
// We limit it.
if (3<depth) return;
QListIterator<QFileInfo> entries(src.entryInfoList());
std::stringstream spaces;
// If you want to indent files by depth
// for (int i=0; i<depth; i++) {
// spaces << ' ';
// }
while (entries.hasNext()) {
QFileInfo entry = entries.next();
QString canpath = entry.canonicalFilePath();
QString relpath = src.relativeFilePath(entry.fileName());
if ((relpath == ".") || (relpath=="..")) {
continue;
}
if (entry.isDir()) {
QDir subdir(canpath);
if (!(subdir==src)) {
listContents(subdir, depth+1);
}
} else {
qDebug() << spaces.str().c_str() << canpath.toUtf8().data();
}
}
}
To use it, you must first strip the /data
directory from your QDir::homePath()
:
QString appFolder(QDir::homePath());
qDebug() << "appFolder = " << appFolder;
appFolder.chop(4);
QDir listSource = appFolder + "app/native";
listContents(listSource);
Thereafter, just check the logs to find the proper path to your database file.
Note though that, if you want to write to the database, you should copy it from the app/native
directory to the data
directory.