The program must connect to the database, or create it. Everything works well when running in Qt Creator, but when you run it through the exe file, nothing happens.
bool database::checkDB() { QString addr; addr = QDir::currentPath() + QString("/database1.db"); if (QFile(addr).exists()) return openDB(addr); else return restoreDB(addr); } bool database::openDB(QString addr) { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(addr); return db.open(); } void database::closeDB() { db.close(); db.removeDatabase(QSqlDatabase::defaultConnection); } bool database::createDB() { QSqlQuery qry; if (qry.exec("CREATE TABLE Worker ( `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE," " `name` TEXT, `date` TEXT, `base_rate` REAL," " `position` TEXT, `username` TEXT, `password` TEXT," " `ch_id` INTEGER )")) { if (qry.exec("insert into Worker(name, username, password) " "VALUES ('admin', 'admin', 'admin')")) return true; else return false; } else return false; } bool database::restoreDB(QString addr) { if (openDB(addr)) return createDB(); else return false; } // Connection occurs in the form constructor.
login::login(QWidget *parent) : QMainWindow(parent), ui(new Ui::login) { ui->setupUi(this); if (db.checkDB()) ui->status->setText("Connected!"); else ui->status->setText("Isn't connect!"); }
plugins/sqldriverswith the necessary dll in the folder with exe, then it will not work - gil9red