Question: When I closed MySql server, how can I understand that mysql server is gone away from my Qt program?

**Edit:**

Here my trial:

When I close MySql, I get these results, and I can't catch that MySql is closed.

My Code Snippet is

```
QSqlQuery query(db);
query.exec("SELECT * From RequestIds");
qDebug()<<query.lastError();
qDebug()<<db.lastError()<<QTime::currentTime();
qDebug()<<db.isOpen();
qDebug()<<db.isValid();

```

and output is:

```
QSqlError(2006, "QMYSQL: Unable to execute query", "MySQL server has gone away") 
QSqlError(-1, "", "") QTime("14:22:58") 
true 
true

```

I don't understand why db.isOpen() returns true.

Answer: 
There is a bug related with QSqlDatabase::isOpen() in Qt. 

<https://bugreports.qt.io/browse/QTBUG-223>
`QSqlQuery::lastError()` should give you an error if your query via `QSqlQuery::exec()` has failed. Also `QSqlDatabase::isOpen()` should report the state of your connection, `QSqlDatabase::lastError()` is also available