C++

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.lastError(); } bool DatabaseManager::deleteDB() { // Close database db.close(); return QFile::remove("database_name_here"); } Execute a query QSqlQuery query; // Create a new table query.exec("CREATE TABLE filelist(fullpath VARCHAR PRIMARY KEY, timestamp VARCHAR)"); // Prepare file Information to insert QFileInfo currentFile = ...; QString filepath = currentFile.absoluteFilePath(); QString timestamp = currentFile.lastModified().date().toString("yyyy-MM"); // Insert a record to the database query.exec("INSERT INTO filelist VALUES('" + filepath + "', '" + timestamp + "')"); // You can also insert a record as following query.prepare("INSERT INTO filelist VALUES(?, ?)"); query.addBindValue(filepath); query.addBindValue(timestamp); query.exec(); query.exec("DROP TABLE filelist");
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. Windows introduces us to messages. A message could be easily described as a pile of data that gets sent to the event handler which then tells the window what to do. A message’s name is prefixed with WM(stands for Windows Message as you might have guessed?). There are a whole lot of messages that a window can handle, however, we’ll only need a few of them. You can use these messages in many ways. For example, the message WM_CREATE, can be used for initialization purposes, it gets sent to the window when it’s created, and WM_PAINT is used when you want to draw something on the screen, and so on, you get the image. Most of the messages get sent to the window automatically, as example when you move your mouse around you send a message to windows, and any other things such as that send messages to windows. You can also send a message to your window yourself, but you’ll probably never need to.