I have got this far (with check connection first only):

mysql.h:
Qt Code:
  1. #ifndef MYSQL_H
  2. #define MYSQL_H
  3.  
  4. #include <QObject>
  5.  
  6. class MySQL : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit MySQL(QObject *parent = 0);
  11. Q_INVOKABLE void checkConnection();
  12.  
  13. signals:
  14.  
  15. public slots:
  16.  
  17. };
  18.  
  19. #endif // MYSQL_H
To copy to clipboard, switch view to plain text mode 

mysql.cpp:
Qt Code:
  1. #include "mysql.h"
  2. #include <QtSql>
  3. #include <QObject>
  4.  
  5. MySQL::MySQL(QObject *parent) :
  6. QObject(parent)
  7. {
  8. }
  9.  
  10. void MySQL::checkConnection()
  11. {
  12. QString result;
  13. // Sets database
  14. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  15. db.setHostName("localhost");
  16. db.setDatabaseName("terminals");
  17. db.setUserName("root");
  18. db.setPassword("");
  19.  
  20. if(db.open()) { qDebug() << "MySQL: Connected"; db.close(); result = "true"; }
  21. else { qDebug() << "MySQL ERROR: " << db.lastError().text(); result = "false"; }
  22.  
  23. }
To copy to clipboard, switch view to plain text mode 

main.qml:
Qt Code:
  1. import QtQuick 2.12
  2. import QtQuick.Controls 2.0
  3. import QtQuick.LocalStorage 2.0
  4. import MySQL 1.0
  5. import 'JavaScript.js' as JS
  6.  
  7. Item {
  8.  
  9. MySQL {
  10. id: sql
  11. }
  12.  
  13. MouseArea {
  14. anchors.fill: parent
  15. onClicked: { sql.checkConnection(); }
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

main.cpp:
Qt Code:
  1. #include <QtCore>
  2. #include <QNetworkAccessManager>
  3. #include <QNetworkReply>
  4. #include <QGuiApplication>
  5. #include <QQmlApplicationEngine>
  6. #include <QtSql>
  7. #include <QtDebug>
  8. #include "mysql.h"
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. QGuiApplication app(argc, argv);
  13.  
  14. qmlRegisterType<MySQL>("MySQL", 1, 0, "MySQL");
  15.  
  16. QQmlApplicationEngine engine;
  17. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  18.  
  19. // Sets path for SQLite
  20. engine.setOfflineStoragePath("C:\\Terminal");
  21.  
  22. return app.exec();
  23. }
To copy to clipboard, switch view to plain text mode 
¨

this works like a charm!

i would like to ad the return ability, so from QML i can do something like:
if(sql.checkConnection()===true) { something } else { somethingelse }
- so it will return result variable from mysql.cpp

how to do this?