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!"); } 
  • 3
    If there is no plugins/sqldrivers with the necessary dll in the folder with exe, then it will not work - gil9red
  • It worked. Thank! - Fedor Razumovsky

2 answers 2

If you run under Windows, it is better to build the application through windeployqt - it will pull all dependencies into the directory with the application. windeployqt comes in Qt, you will find it through a search, if required - write it in PATH.

If running for Linux, make sure that dynamic libraries, including the database of connectors, are available in LD_LIBRARY_PATH. For Linux, there is a certain reason to install Qt from packages if you do not need any completely new features. Although through Qt Chooser everything is also perfectly integrated.

If the .exe file does not start, to run the application without an IDE, then the missing dll files should be placed in the folder with this executable.

it is necessary that the release folder contains the missing dll, and copy them from the C: // Qt / ... / mingw48-32 / bin folder

read more here: http://blog.harrix.org/article/1015