From 5d5e8cfae4de11102e4946b17c4bb20d86f275ae Mon Sep 17 00:00:00 2001
From: Federico Terraneo <fede.tft@miosix.org>
Date: Mon, 24 Oct 2022 23:51:41 +0200
Subject: [PATCH] Update Qt simulator to Qt5

---
 _tools/qtsimulator/CMakeLists.txt  | 7 +++----
 _tools/qtsimulator/qtsimulator.cpp | 2 +-
 _tools/qtsimulator/window.cpp      | 8 ++++----
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/_tools/qtsimulator/CMakeLists.txt b/_tools/qtsimulator/CMakeLists.txt
index 7574c85..595a109 100644
--- a/_tools/qtsimulator/CMakeLists.txt
+++ b/_tools/qtsimulator/CMakeLists.txt
@@ -73,15 +73,14 @@ include_directories(../..)
 include_directories(../../..)
 add_definitions(-DMXGUI_LIBRARY)
 
-find_package(Qt4 REQUIRED)
-include(${QT_USE_FILE})
-qt4_wrap_cpp(FOO_HEADERS_MOC ${FOO_HEADERS})
+find_package(Qt5 COMPONENTS Widgets REQUIRED)
+qt5_wrap_cpp(FOO_HEADERS_MOC ${FOO_HEADERS})
 if(APPLE)
 	add_executable(qtsimulator MACOSX_BUNDLE ${LIB_SRCS} ${FOO_SRCS} ${IMG_OUT} ${FOO_HEADERS_MOC})
 else()
 	add_executable(qtsimulator ${LIB_SRCS} ${FOO_SRCS} ${IMG_OUT} ${FOO_HEADERS_MOC})
 endif()
-target_link_libraries(qtsimulator ${QT_LIBRARIES})
+target_link_libraries(qtsimulator Qt5::Widgets)
 set(BOOST_LIBS thread filesystem system)
 find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED)
 target_link_libraries(qtsimulator ${Boost_LIBRARIES})
diff --git a/_tools/qtsimulator/qtsimulator.cpp b/_tools/qtsimulator/qtsimulator.cpp
index 7d9519c..255586f 100644
--- a/_tools/qtsimulator/qtsimulator.cpp
+++ b/_tools/qtsimulator/qtsimulator.cpp
@@ -1,5 +1,5 @@
 
-#include <QtGui/QApplication>
+#include <QtWidgets/QApplication>
 #include <boost/filesystem.hpp>
 #include "window.h"
 
diff --git a/_tools/qtsimulator/window.cpp b/_tools/qtsimulator/window.cpp
index 8d7ded6..d917070 100644
--- a/_tools/qtsimulator/window.cpp
+++ b/_tools/qtsimulator/window.cpp
@@ -63,7 +63,7 @@ Window::Window(QWidget *parent): QWidget(parent),
     this->setWindowTitle(tr("Mxgui simulator"));
     this->show();
     QTBackend& qb=QTBackend::instance();
-    std::memcpy(image.bits(),qb.getFrameBuffer().getData(),image.byteCount());
+    std::memcpy(image.bits(),qb.getFrameBuffer().getData(),image.sizeInBytes());
     this->update();
     qb.start(sender);
 }
@@ -71,7 +71,7 @@ Window::Window(QWidget *parent): QWidget(parent),
 void Window::updateFrameBuffer()
 {
     FrameBuffer& buffer=QTBackend::instance().getFrameBuffer();
-    std::memcpy(image.bits(),buffer.getData(),image.byteCount());
+    std::memcpy(image.bits(),buffer.getData(),image.sizeInBytes());
     this->update();
 }
 
@@ -140,7 +140,7 @@ void Window::keyPressEvent(QKeyEvent *event)
     }
     QString s=event->text();
     if(s.size()==0) return;
-    char k=s[0].toAscii();
+    char k=s[0].toLatin1();
     addEvent(Event(EventType::KeyDown,k));
 }
 
@@ -154,6 +154,6 @@ void Window::keyReleaseEvent(QKeyEvent *event)
     }
     QString s=event->text();
     if(s.size()==0) return;
-    char k=s[0].toAscii();
+    char k=s[0].toLatin1();
     addEvent(Event(EventType::KeyUp,k));
 }
-- 
GitLab