C++ Libraries

Cross-platform C++ libraries ACE,Boost,POCO,Qt

MSYS2

MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software.

Download the installer

• Run the installer.
• Enter your desired Installation Folder.
• MSYS2 is ready!
• You are ready to use MSYS2 terminal for the UCRT64 environment.
• It’s time to install some tools. Run the following command:

pacman -S mingw-w64-ucrt-x86_64-gcc

• When it’s complete you can call gcc to verify your installation.

gcc --version

gcc.exe (Rev10, Built by MSYS2 project) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

• To update all packages run the following command:

pacman -Suy

• Pruning the package cache

paccache -r

• Finding a package (for example vim)

pacman -Ss vim

• Installing a package

pacman -S vim

• Uninstalling a package

pacman -U vim

• Finding dependencies of a package

pactree vim

It consists of a command line terminal called mintty, bash, version control systems like git and subversion, tools like tar and awk and even build systems like autotools, all based on a modified version of Cygwin. Despite some of these central parts being based on Cygwin, the main focus of MSYS2 is to provide a build environment for native Windows software and the Cygwin-using parts are kept at a minimum. MSYS2 provides up-to-date native builds for GCC, mingw-w64, CPython, CMake, Meson, OpenSSL, FFmpeg, Rust, Ruby, just to name a few.

Sourcetrail a cross-platform source explorer for C/C++ and Java*

Sourcetrail a cross-platform source explorer, great and powerful tool to have it.
I personally recommend it for any junior or senior developers. A cross-platform source explorer for C/C++ and Java* deserves a blog post to reach more developers as well as serious commercial customers.

Watch Sourcetrail on Youtube

* Free for non-commercial use

SQLite – How to use fundamental functions in C++

SQLite operations in C++
This tutorial aimed to demonstrate how to use SQLite database operations such as CREATE, INSERT, UPDATE, SELECT and DELETE in C++. Since the appearance first smartphone and other mobile devices SQLite become most widely deployed and used database engine in the world. Precise numbers are difficult to obtain but SQLite is likely used more than all other database engines combined. We can find SQLite in every Android device, iPhone and iOS device, Mac, Windows10, Firefox, Chrome, Safari, Skype, Dropbox, TurboTax, QuickBooks, PHP, Python, television sets, set-top cable boxes and many automotive multimedia systems.

It’s an open-source SQL database engine. You can download the source code or precompiled binaries depending your requirements. You might also need to add [-lsqlite3] and [-std=c++17] to successfully compile, create an executable file. Each of the following source code available on my git repository.

github.com/lnrsoft/sqlite3_cpp_basics_updated

Use this link local_db.sqlite (557 downloads) if you would like to download the local_db.sqlite file that I used in this tutorial.

Step 1 – The first thing we need to do is to create the actual database file that we will use in this article. I called sqltdemo.db in our case.

#include 
#include 
#include 


int main() {
    sqlite3* db;
    auto op = sqlite3_open("local_db.sqlite", &db);
    auto cl = sqlite3_close(db);
    if(op) {
	std::cerr << "SQLite ERROR: " << sqlite3_errmsg(db) << std::endl;
	return (0);
    } else {
	std::cout << "SQLite local db has been opened successfully."
	          << std::endl;
    }
    if(cl) {
	std::cerr << "SQLite ERROR: " << sqlite3_errmsg(db) << std::endl;
	return (0);
    } else {
	std::cout << "SQLite local db has been closed successfully."
	          << std::endl;
    }
}

Compile and run our source code to create the local_db.sqlite with the following command. Here we link our code with the sqlite3 library that will create our db file.

$ clang++ 01_openDB.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
SQLite local db has been opened successfully.
SQLite local db has been closed successfully.

Verify our result:

$ ls -la
-rw-r--r--   1 rolandihasz staff   605 Mar  1 21:05 01_openDB.cpp
-rw-r--r--   1 rolandihasz staff 21606 Mar  1 21:06 local_db.sqlite
-rwxr-xr-x   1 rolandihasz staff  8660 Mar  1 21:06 a.out

Step 2 – CREATE TABLE

#include 
#include 
#include 

static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
    int i;
    for(i = 0; i < argc; i++) {
        std::cerr << azColName[i] << argv[i] << argv[i] << "NULL";
    }
    std::cout << std::endl;
    return 0;
}

int main()
{
    sqlite3 *db;
    char *zErrMsg = nullptr;
    const char *sql;
    auto rc = sqlite3_open("local_db.sqlite", &db);
    if(rc) {
        std::cerr << "Failed open database: " << sqlite3_errmsg(db)
                  << std::endl;
        return (0);
    }
    else {
        std::cerr << "Database successfully opened" << std::endl;
    }
    sql = "CREATE TABLE CANDIDATE("
          "ID INT PRIMARY KEY     NOT NULL,"
          "NAME           TEXT    NOT NULL,"
          "AGE            INT     NOT NULL,"
          "ROLE           TEXT    NOT NULL,"
          "SALARY         TEXT    NOT NULL);";
    rc = sqlite3_exec(db, sql, callback, nullptr, &zErrMsg);
    if(rc != SQLITE_OK) {
        std::cerr << "SQL error: " << zErrMsg << std::endl;
        sqlite3_free(&zErrMsg);
    }
    else {
        std::cerr << "Table successfully created" << std::endl;
    }
    sqlite3_close(db);
    return 0;
}

Compile and run.

$ clang++ 02_sqlite3_create_table.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
Database successfully opened
Table successfully created

Step 3 – INSERT INTO our CANDIDATE TABLE

 
#include 
#include 
#include 

static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
    int i;
    for(i = 0; i < argc; i++) {
        std::cerr << azColName[i] << argv[i] << argv[i] << "NULL";
    }
    std::cout << std::endl;
    return 0;
}
int main()
{
    sqlite3 *db;
    char *zErrMsg = nullptr;
    int rc;
    const char *sql;
    rc = sqlite3_open("local_db.sqlite", &db);
    if(rc) {
        std::cerr << "Failed open database: " << sqlite3_errmsg(db)
                  << std::endl;
        return (0);
    }
    else {
        std::cerr << "Database successfully opened" << std::endl;
    }
    sql = "INSERT INTO CANDIDATE (ID,NAME,AGE,ROLE,SALARY) "
          "VALUES (1, 'Daniel', 29, 'CCO', 130000 ); "
          "INSERT INTO CANDIDATE (ID,NAME,AGE,ROLE,SALARY) "
          "VALUES (2, 'Roland', 35, 'CTO', 175000 ); "
          "INSERT INTO CANDIDATE (ID,NAME,AGE,ROLE,SALARY)"
          "VALUES (3, 'Leslie', 33, 'CEO', 200000 );";
    rc = sqlite3_exec(db, sql, callback, nullptr, &zErrMsg);
    if(rc != SQLITE_OK) {
        std::cerr << "SQL error: " << zErrMsg << std::endl;
        sqlite3_free(zErrMsg);
    }
    else {
        std::cerr << "Records created successfully" << std::endl;
    }
    sqlite3_close(db);
    return 0;
}

Compile and run.

$ clang++ 03_sqlite3_insert.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
Database successfully opened
Records created successfully

Step 4 – Fetch and display records from the company CANDIDATE TABLE. In this scenario we use a callback function that obtains results from SELECT statement.

//callback function declaration
typedef int (*sqlite3_callback)(
   void*,    /* Data provided in the 4th argument of sqlite3_exec() */
   int,      /* The number of columns in row */
   char**,   /* An array of strings representing fields in the row */
   char**    /* An array of strings representing column names */
);
#include 
#include 
#include 
#include 
#include 


static int callback(void *data, int argc, char **argv, char **azColName)
{
    fprintf(stderr, "\nCallback function call: ", &data);
    for(auto i = 0; i < argc; i++) {
        printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    return 0;
}

int main()
{
    sqlite3 *db;
    char *zErrMsg = nullptr;
    int rc;
    const char *sql;
    const char *data = "Callback function call";
    rc = sqlite3_open("local_db.sqlite", &db);
    if(rc) {
        std::cerr << "Failed open database: " << sqlite3_errmsg(db)
                  << std::endl;
        return (0);
    }
    else {
        std::cerr << "Database successfully opened" << std::endl;
    }
    sql = "SELECT * from CANDIDATE";
    rc = sqlite3_exec(db, sql, callback, &data, &zErrMsg);
    if(rc != SQLITE_OK) {
        std::cerr << "SQL error: " << zErrMsg << std::endl;
        sqlite3_free(zErrMsg);
    }
    else {
        std::cout << "\nExecution completed successfully" << std::endl;
    }
    sqlite3_close(db);
    return 0;
}

Compile and run.

$ clang++ 04_sqlite3_select_operation.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
Database successfully opened

Callback function call: ID = 1
NAME = Daniel
AGE = 29
ROLE = CCO
SALARY = 130000

Callback function call: ID = 2
NAME = Roland
AGE = 35
ROLE = CTO
SALARY = 175000

Callback function call: ID = 3
NAME = Leslie
AGE = 33
ROLE = CEO
SALARY = 200000

Execution completed successfully

Step 5 – Using UPDATE statement to update any records in our CANDIDATE table.

#include 
#include 
#include 
#include 
#include 

static int callback(void *data, int argc, char **argv, char **azColName)
{
    fprintf(stderr, "\nCallback function call: ", &data);
    for(auto i = 0; i < argc; i++) {
        printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    return 0;
}

int main()
{
    sqlite3 *db;
    char *zErrMsg = nullptr;
    int rc;
    const char *sql;
    const char *data = "Callback function call";
    rc = sqlite3_open("local_db.sqlite", &db);
    if(rc) {
        std::cerr << "Failed open database: " << sqlite3_errmsg(db)
                  << std::endl;
        return (0);
    }
    else {
        std::cout << "Database successfully opened" << std::endl;
    }
    sql = "UPDATE CANDIDATE set SALARY = 150000 where ID=1; "
          "SELECT * from CANDIDATE";
    rc = sqlite3_exec(db, sql, callback, &data, &zErrMsg);
    if(rc != SQLITE_OK) {
        std::cerr << "SQL error: " << zErrMsg << std::endl;
        sqlite3_free(zErrMsg);
    }
    else {
        std::cout << "Execution completed successfully" << std::endl;
    }
    sqlite3_close(db);
    return 0;
}

Compile and run.

$ clang++ 05_sqlite3_update_operation.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
Database successfully opened

Callback function call: ID = 1

NAME = Daniel
AGE = 29
ROLE = CCO
SALARY = 150000

Callback function call: ID = 2
NAME = Roland
AGE = 35
ROLE = CTO
SALARY = 175000

Callback function call: ID = 3
NAME = Leslie
AGE = 33
ROLE = CEO
SALARY = 200000

Execution completed successfully

Step 6 – DELETE statement can delete any records from the CANDIDATE table.

#include 
#include 
#include 
#include 
#include 

static int callback(void *data, int argc, char **argv, char **azColName)
{
    fprintf(stderr, "\nCallback function call: ", &data);
    for(auto i = 0; i < argc; i++) {
        printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    return 0;
}

int main()
{
    sqlite3 *db;
    char *zErrMsg = nullptr;
    int rc;
    const char *sql;
    const char *data = "Callback function call";
    rc = sqlite3_open("local_db.sqlite", &db);
    if(rc) {
        std::cerr << "Failed open database: " << sqlite3_errmsg(db)
                  << std::endl;
        return (0);
    }
    else {
        std::cerr << "Database successfully opened" << std::endl;
    }
    sql = "DELETE from CANDIDATE where ID=2; "
          "SELECT * from CANDIDATE";
    rc = sqlite3_exec(db, sql, callback, &data, &zErrMsg);
    if(rc != SQLITE_OK) {
        std::cerr << "SQL error: " << zErrMsg << std::endl;
        sqlite3_free(zErrMsg);
    }
    else {
        std::cout << "\nExecution completed successfully" << std::endl;
    }
    sqlite3_close(db);
    return 0;
}

Compile and run.

$ clang++ 06_sqlite3_delete_operation.cpp -Wall -Wextra -lsqlite3 -std=c++17
$ ./a.out
Database successfully opened

Callback function call: ID = 1
NAME = Daniel
AGE = 29
ROLE = CCO
SALARY = 150000

Callback function call: ID = 3
NAME = Leslie
AGE = 33
ROLE = CEO
SALARY = 200000

Execution completed successfully

I recommend you to check the official SQLite documentation at sqlite.org for more advance SQLite features and options and support. For further info about using sql with c++ you might found it useful to read me previous post of  a simple Qt tool to test QSqlDatabase access connection to a MySQL database. I created this simple Qt command line tool to test connection between Qt client applications and a remote Mysql Server. The code includes Secure Sockets Layer (SSL) support to test secure connection. The QSqlDatabase class provides an interface for accessing a database through a connection where an instance of QSqlDatabase represents the connection. The connection provides access to the database via one of the supported database drivers, which are derived from QSqlDriver.

Alternatively, we can subclass your own database driver from QSqlDriver. My next post will be an article how to write your own database driver in Qt for Unix, OSX and Windows platforms.

SPECIFY ADDITIONAL COMPILER OPTIONS IN QTCREATOR OR SIMPLE ADD THEM TO QMAKE

List of build-specific variants to specify your Qt project.

QMAKE_CC                      = gcc
QMAKE_LEX                     = flex
QMAKE_LEXFLAGS                =
QMAKE_YACC                    = byacc
QMAKE_YACCFLAGS               = -d
QMAKE_CFLAGS                  =
QMAKE_CFLAGS_DEPS             = -M
QMAKE_CFLAGS_WARN_ON          = -Wall
QMAKE_CFLAGS_WARN_OFF         = -w
QMAKE_CFLAGS_RELEASE          = -O2
QMAKE_CFLAGS_DEBUG            = -g
QMAKE_CFLAGS_YACC             = -Wno-unused -Wno-parentheses
QMAKE_CXX                     = g++
QMAKE_CXXFLAGS                = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS           = $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON        = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF       = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE        = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG          = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_YACC           = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD         = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_RTTI_ON        = -frtti
QMAKE_CXXFLAGS_RTTI_OFF       = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON  = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions

QSqlDatabase connection testing tool

QSqlDatabase connection access

A simple command line tool to test connection between Qt client applications and a remote Mysql Server. The code includes Secure Sockets Layer (SSL) support to test secure connection. The QSqlDatabase class provides an interface for accessing a database through a connection. An instance of QSqlDatabase represents the connection. The connection provides access to the database via one of the supported database drivers (MySQL in our case), which are derived from QSqlDriver. Alternatively, we can subclass your own database driver from QSqlDriver. I’ll post an another article about how to write your own database driver in Qt for Unix, OSX and Windows platforms. It’s recommend to write your own database driver especially when you planning to deploy your application in different platforms. It’s simply because there could be surprises especially on client deploying your application that using one of the supported database drivers due to missing dependencies or environmental variables.

Software prerequisites:
Remote MySQL server version: 5.7 or above
Qt version: Qt_5_7_1 or above
OpenSSL 1.0.x or above the for SSL feature

How to use it:
1. I simply run the mysql_conn_test_database.sql SQL script file to create a test database on the remote server.
2. Set the hostname or IP, port number, username and password. You migth need to create a new database user for this purpose.
[You will need to create SSL certificates for the database server and client in order to test SSL Feature on the MySQL Server.]
3. If everthing is set just simple build and run the project in your QtCreator.

If everything goes well you will recieve the following feedback from your terminal:


QSqlDatabase connection test tool was created and written by Roland Ihasz and it is licensed under the GNU General Public License (GPL) Version 2 or above.

Check out on GitHub. https://github.com/lnrsoft/QSqlDatabase-connection-test-tool

 mysql_db_connection_test.pro

# (c)  Roland Ihasz - https://github.com/lnrsoft   

QT += core
QT -= gui
QT += sql
QT += sql widgets

CONFIG += c++11
CONFIG += console       
#CONFIG -= console      
CONFIG -= app_bundle

TEMPLATE = app

TARGET = mysql_db_connection_test

SOURCES += main.cpp

QTPLUGIN += sqldrivers

QMAKE_CXXFLAGS += -std=c++11

 main.cpp

// (c)  Roland Ihasz - https://github.com/lnrsoft

#include <QSqlDatabase>
#include <QApplication>
#include <QSqlRecord>
#include <QSqlError>
#include <QSqlQuery>
#include <QDebug>
#include <QtCore>
#include <QtSql>

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("192.168.1.100");        // your host or ip name
        db.setPort(3306);                       // port number
        db.setDatabaseName("mysql_conn_test");  // db name
        db.setUserName("username");             // db username
        db.setPassword("password");             // db password
        //----------Additional-SSL-Feature-for-secure-database-connection----------
        //  db.setConnectOptions(
        //    "SSL_KEY=/Users/lnrsoft/repository/mysql_db_conn_test/client-key.pem;"
        //    "SSL_CERT=/Users/lnrsoft/repository/mysql_db_conn_test/client-cert.pem;"
        //    "SSL_CA=/Users/lnrsoft/repository/mysql_db_conn_test/ca-cert.pem;"
        //    "SSL_CIPHER=DHE-RSA-AES256-SHA;");
        //----------Additional-SSL-Feature-for-secure-database-connection----------
        if(!db.open()) {
            qDebug() << "\nDATABASE CONNECTION UNSUCCESSFUL."
                     << "\nlastError: " << db.lastError().text() <<"\n";
            return 0;
        }
        if(db.open()) {
            qDebug() << "\nSUCCESSFULLY CONNECTED TO THE DATABASE SERVER.";
            QSqlQuery query(
                "SELECT "
                "dataTable.ID, "
                "dataTable.x1, "
                "dataTable.y1, "
                "dataTable.z1, "
                "dataTable.t "
                "FROM mysql_conn_test.dataTable");
            QSqlRecord rec1 = query.record();
            QSqlRecord rec2 = query.record();
            QSqlRecord rec3 = query.record();
            QSqlRecord rec4 = query.record();
            QSqlRecord rec5 = query.record();
            qDebug() << "NUMBER OF ROWS: " << query.size();   // Return number of rows
            int productCode1 = rec1.indexOf("ID");
            int productCode2 = rec2.indexOf("x1");
            int productCode3 = rec3.indexOf("y1");
            int productCode4 = rec4.indexOf("z1");
            int productCode5 = rec5.indexOf("t");
            qDebug() << "====================================================================================";
            while(query.next()) {
                qDebug() << "ROW NUMBER"
                         << query.value(productCode1).toString() << ""
                         << query.value(productCode2).toString() << ""
                         << query.value(productCode3).toString() << ""
                         << query.value(productCode4).toString() << ""
                         << query.value(productCode5).toString();
            }
            qDebug() << "====================================================================================";
            qDebug() << "COMPLETE...";
            return 0;
        }
    }
}

 mysql_conn_test_database.sql

/*	(c)  Roland Ihasz - https://github.com/lnrsoft	*/

DROP DATABASE IF EXISTS `mysql_conn_test`;

CREATE DATABASE IF NOT EXISTS `mysql_conn_test` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `mysql_conn_test`;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

DROP TABLE IF EXISTS `dataTable`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `dataTable` (
  `ID` int(1) NOT NULL,
  `x1` double NOT NULL,
  `y1` double NOT NULL,
  `z1` double NOT NULL,
  `t` int(16) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

LOCK TABLES `dataTable` WRITE;
/*!40000 ALTER TABLE `dataTable` DISABLE KEYS */;
INSERT INTO `dataTable` VALUES (1,0.3352925219759345,0.336742962207645,0.3117983819916844,2),(2,0.3351856799423695,0.334428142439574,0.3127960397861898,5),(3,0.3592007360234857,0.314406356215476,0.3792905477248132,9);
/*!40000 ALTER TABLE `dataTable` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

Alternatively, use the following shorter source code to check the connection without any sql query.
 QSqlDatabase connection test tool without query

// (c)  Roland Ihasz - https://github.com/lnrsoft   

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDebug>
#include <QDebug>
#include <QtCore>
#include <QtSql>

int main(int argc, char* argv[])
{
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("192.168.1.100");        // host or ip name
    db.setPort(3306);                       // port number
    db.setDatabaseName("mysql_conn_test");  // db name
    db.setUserName("username");             // db username
    db.setPassword("password");             // db password
    if(!db.open()) {
        qDebug() << "\nDATABASE CONNECTION UNSUCCESSFUL."
                 << "\nlastError: " << db.lastError().text() <<"\n";
        return 0;
    }
    if(db.open()) {
        qDebug() << "\nSUCCESSFULLY CONNECTED TO THE DATABASE SERVER.\n";
        return 0;
    }
}