Project file (.pro) Add the following line to your .pro file QT += sql Header #include <QtSql/QSqlDatabase> #include <QtSql/QSqlError> class DatabaseManager { public: DatabaseManager(); ~DatabaseManager(); public: bool openDB(); bool deleteDB(); QSqlError lastError(); private: QSqlDatabase db; }; Source bool DatabaseManager::openDB() { // Find QSLite driver db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("database_name_here"); // Open databasee return db.open(); } QSqlError DatabaseManager::lastError() { // If opening database has failed user can ask // error description by QSqlError::text() return db.
Welcome to the first windows tutorial. In this tutorial, I’ll give you the basic information on how to code in windows and we’ll go over a few important details first. The basic windows program has two important functions inside. The first one is the event handler(I’ll talk about this one later on) and the second one is the main function(WinMain from now on). WinMain is similar to DOS’ main function, in fact, WinMain is called from the DOS main function but in windows, we don’t have access to the DOS main; everything is covered up by windows.