Hello to everyone,
I have a problem reading from a MySql database some values (DataTime type). Using the dynamic installation (Qt 5.15.7 "out of the box") I have no problem, but trying to compile it with the static version, Qt can't resolve its value.
I created a very simple database, just to show this behaviour:
id_event , event_name, event_date (format: DATETIME)
'0', 'Beethoven Concert' '2022-08-15 21:15:00'
'1' 'Vivaldi Concert' '2022-08-22 21:30:00'
'2 'Bach Concert' '2022-08-08 21:00:00'
Now I run this simple code:
mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include "QtSql/QSql"
  6. #include <QtSql/QSqlDatabase>
  7. #include <QtSql/QSqlTableModel>
  8. #include <QtSql/QSqlError>
  9. #include <QtSql/QSqlQuery>
  10. #include <QDebug>
  11. #include <QtCore>
  12. #include <QDate>
  13. #include <QMessageBox>
  14.  
  15. QT_BEGIN_NAMESPACE
  16. namespace Ui { class MainWindow; }
  17. QT_END_NAMESPACE
  18.  
  19. class MainWindow : public QMainWindow
  20. {
  21. Q_OBJECT
  22.  
  23. public:
  24. MainWindow(QWidget *parent = nullptr);
  25. ~MainWindow();
  26.  
  27. private:
  28. Ui::MainWindow *ui;
  29.  
  30. };
  31. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 
mainwindow.cpp:
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtSql/QSqlQuery>
  4.  
  5. MainWindow::MainWindow(QWidget *parent)
  6. : QMainWindow(parent),
  7. ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10. QSqlDatabase eventDB;
  11. eventDB = QSqlDatabase::addDatabase("QMYSQL");
  12. eventDB.setHostName("localhost");
  13. eventDB.setDatabaseName("event");
  14. eventDB.setPort(3306);
  15. eventDB.setUserName("user");
  16. eventDB.setPassword("user_pwd123");
  17. if (!eventDB.open()) {
  18. QMessageBox::critical(this,"Error",eventDB.lastError().text());
  19. return;
  20. }
  21.  
  22. QSqlQuery * qryEvent= new QSqlQuery();
  23. qryEvent->prepare("SELECT event_name,event_date FROM event WHERE id_event=0");
  24. qryEvent->exec();
  25. qryEvent->first();
  26. QString event=qryEvent->value(0).toString();
  27.  
  28.  
  29. QDateTime time_event=qryEvent->value(1).toDateTime();
  30.  
  31. QString Date=time_event.toString("dd-MM-yyyy");
  32. QString Hour=time_event.toString("hh:mm");
  33.  
  34. ui->Event->setText(event);
  35. ui->Date->setText(Date);
  36. ui->Hour->setText(Hour);
  37. }
  38.  
  39. MainWindow::~MainWindow()
  40. {
  41. delete ui;
  42. }
To copy to clipboard, switch view to plain text mode 

I have a simple form to show the result of "event","Date" and "Hour" variables and this is the result.
With Dynamic Qt 5.15.7:
dynamic_QT5.jpg
while in Static Qt 5.15.7 (adding a qDebug for checking "Date" value:
Static_QT.png
Any suggestion?
Thanks a lot!