Application crashing after calling a method
<p>I want to return a <code>QString</code> value from a function that exists in class called <code>DB</code> in my <code>MainWindow</code> class, but it always crashes the application.</p>

<p><strong>db.h</strong></p>

<pre><code>#ifndef DB_H
#define DB_H

#include &lt;QMainWindow&gt;
#include &lt;QtSQl&gt;
#include &lt;QSqlQuery&gt;
#include &lt;QSqlError&gt;
#include &lt;QObject&gt;
#include &lt;QDialog&gt;

class DB : public QMainWindow
{
    Q_OBJECT
public:
    explicit DB(QWidget *parent = 0);

    QString getDriver() const;
    void setDriver(const QString &amp;value);

private:
    QString Driver="test";

signals:

public slots:
};

#endif // DB_H
</code></pre>

<p>and this is <strong>db.cpp</strong></p>

<pre><code>#include "db.h"

DB::DB(QWidget *parent) : QMainWindow(parent)
{

}

QString DB::getDriver() const
{
    return Driver;
}


void DB::setDriver(const QString &amp;value)
{
    Driver = value;
}
</code></pre>

<p><strong>mainwindow.h</strong></p>

<pre><code>#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include &lt;QMainWindow&gt;
#include &lt;QDebug&gt;
#include &lt;QFileInfo&gt;
#include &lt;QDialog&gt;
#include &lt;QObject&gt;
#include "Db.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    DB *conn;

private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H
</code></pre>

<p><strong>mainwindow.cpp</strong></p>

<pre><code>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include &lt;QDebug&gt;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QString driverfromdb = conn-&gt;getDriver();
    qDebug() &lt;&lt; driverfromdb;
}
</code></pre>

<p>And this what happen when I click the pushbutton: <a href="http://i.stack.imgur.com/nzx3L.png" rel="nofollow">image</a></p>