I made a very simple program to open a sqlite3 database and create a sample table in it. I wrote this code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlQuery>
#include <QSqlError>
#include <QMessageBox>
#include <QStandardPaths>
#include <QFile>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QFile file(QStandardPaths::displayName(QStandardPaths::AppDataLocation) + "/library.db");
if(file.open(QFile::ReadWrite))
QMessageBox::information(this, "", "Successfully created database");
db.setDatabaseName(file.fileName());
db.setHostName("Test");
if(db.open())
{
QSqlQuery query;
if(!query.exec("create table if not exists test(name text not null)"))
QMessageBox::critical(this, "Oops!", "Unable to create table: " + query.lastError().text());
}
else
QMessageBox::critical(this, "Oops!", "Unable to open database: " + db.lastError().text());
}
MainWindow::~MainWindow()
{
delete ui;
}
I tested the code in debug mode (dektop kit) and it worked. I then, tried debug mode in Universal Windows Platform 32 bit kit(64 bit doesn't work either). But this time, although the code compiles fine and the app is deployed too, the database is not created. And it shows the error: "out of memory. Error opening database". Is it something about UWP that I am missing?
I checked the build folder of the project, and NO database was created.
I am using 64-bit windows 10