M
M
mgkirs2017-04-19 18:10:06
iPhone
mgkirs, 2017-04-19 18:10:06

How to put the database together with the application?

if(QFile::exists(":db/db.sl3")){
    QSqlDatabase b = QSqlDatabase::addDatabase("QSQLITE");
    b.setDatabaseName(":db/db.sl3");
    qDebug()<<"Database: ";
    if(!b.open()){
    qDebug()<<b.lastError().text();
    }else{
    qDebug()<<"All ok select sqlite_version() AS sqlite_version";
    }
}else{
    qDebug()<<"File not found";
}

qrc option is not suitable, SQLite requires the full path to the database to work, or will throw a database driver level error.
How are xml files, melon databases assembled in a place with applications in general. And how can one get their way.
As far as I understood it is called: "installation base"
PS now trying to find a solution for iphone

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mgkirs, 2017-04-22
@mgkirs

Just copied from qrc to AppDataLocation

QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
if(!QFile::exists("db.sl3")){
    QFile::copy(":db/db.sl3","db.sl3");
}else{
    qDebug()<<"File found"; }
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
nwtb.setDatabaseName("JWS.sl3");
if(!db.open()){
qDebug()<<nwtb.lastError().text();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question