QT 5.7 MySQL driver not loaded
<p>There are quite a few questions/answers relating to this topic but I have tried all the posted solutions:</p>
<p><strong>System Info :</strong></p>
<ul>
<li><p>Ubuntu Gnome 16.10 x86-64</p>
</li>
<li><p>MYSQL Version:</p>
<p>mysql  Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using  EditLine wrapper</p>
</li>
</ul>
<p><strong>Note:</strong>
Each attempt ends up with this error message</p>
<blockquote>
<p>QSqlDatabase: QMYSQL driver not loaded</p>
<p>QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7</p>
</blockquote>
<p><strong>Tried:</strong></p>
<p>Installing Packages for QT 4:</p>
<pre><code>apt-get install libqt4-sql-mysql
</code></pre>
<p>Installing Packages for QT 5:</p>
<pre><code>apt-get install libqt5sql5-mysql
</code></pre>
<p>Removing and installing <code>libmysqlclient-dev</code></p>
<pre><code>$ sudo apt-get purge libmysqlclient-dev
$ sudo apt-get install libmysqlclient-dev
</code></pre>
<p>Tried creating <a href="http://www.qtcentre.org/threads/55365-QSqlDatabase-QMYSQL-driver-not-loaded-but-available?p=259924#post259924" rel="nofollow noreferrer">symlink</a> as shown below:</p>
<pre><code>#locate libmysqlclient file

$ locate libmysqlclient

/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.2
/usr/share/doc/libmysqlclient20
/usr/share/doc/libmysqlclient20/NEWS.Debian.gz
/usr/share/doc/libmysqlclient20/changelog.Debian.gz
/usr/share/doc/libmysqlclient20/copyright
/var/cache/apt/archives/libmysqlclient20_5.7.15-0ubuntu2_amd64.deb
/var/lib/dpkg/info/libmysqlclient20:amd64.list
/var/lib/dpkg/info/libmysqlclient20:amd64.md5sums
/var/lib/dpkg/info/libmysqlclient20:amd64.shlibs
/var/lib/dpkg/info/libmysqlclient20:amd64.symbols
/var/lib/dpkg/info/libmysqlclient20:amd64.triggers

#cd to the dir, and create link
$ cd /usr/lib/x86_64-linux-gnu
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 libmysqlclient_r.so
</code></pre>
<p><em>this one I just incase</em></p>
<pre><code>$ sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 libmysqlclient_r.so 
</code></pre>
<p>Contents of Plugin directory:</p>
<pre><code>ll /opt/qt/QT-5.7/5.7/gcc_64/plugins/sqldrivers/
total 988
drwxrwxr-x 1 cx cx     84 Oct 17 15:58 ./
drwxrwxr-x 1 cx cx    504 Oct 17 15:58 ../
-rwxr-xr-x 1 cx cx 851008 Jun 10 11:10 libqsqlite.so*
-rwxr-xr-x 1 cx cx  75424 Jun 10 11:10 libqsqlmysql.so*
-rwxr-xr-x 1 cx cx  79368 Jun 10 11:10 libqsqlpsql.so*
</code></pre>
<p><strong>Project Info:</strong></p>
<p><strong>Added to .pro file:</strong></p>
<pre><code>QT += sql
</code></pre>
<p><strong>Code:</strong></p>
<pre><code>#include &lt;QtSql&gt;
#include &lt;QSqlDriver&gt;
#include &lt;qsqldatabase.h&gt;
#include &lt;QSqlError&gt;
#include &lt;QPluginLoader&gt;
#include &lt;cstdio&gt;

using namespace std;

//some irrelevant project code in between

QString rootPass = getRootPassword();
    QSqlDatabase db = QSqlDatabase::addDatabase(&quot;QMYSQL&quot;);
    db.setHostName(&quot;localhost&quot;);
    //    db.setDatabaseName(DBName);
    db.setUserName(&quot;root&quot;);
    db.setPassword(rootPass);

    if (!db.isValid()){
        QSqlError err = db.lastError();
        cout &lt;&lt; endl &lt;&lt; &quot;!DB ERROR: &quot;&lt;&lt; err.text();
        cout.flush();
    }

    //qsqlerror err: unused4 : 21985
    //qsqlerror err: unused3 : 2757134240 (2757134240)

    if (db.open()){
        //do things to database
    }
    else
    {
        cout &lt;&lt; &quot;error opening database&quot; &lt;&lt; endl;
    }
</code></pre>
<p>In my project, I have tried:</p>
<pre><code>    QSqlDatabase db = QSqlDatabase::addDatabase(&quot;QMYSQL&quot;);
</code></pre>
<p>and</p>
<pre><code>    QSqlDatabase db = QSqlDatabase::addDatabase(&quot;QMYSQL3&quot;);
</code></pre>
<p>just in case, no luck</p>
<p>I have also copied the <code>libmysqlclient.so</code> file to my plugins directory, also did not work (tried this incase of a library path missing,etc.)</p>
<p>I have no idea how to continue further, any suggestions would be helpful</p>