From 6c20bac7ddd72a8690eccad14ef77b95a7dbe127 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 20 May 2021 14:03:55 +1000 Subject: [PATCH] Qt: Support Qt 6 --- src/duckstation-qt/autoupdaterdialog.cpp | 2 + src/duckstation-qt/duckstation-qt.vcxproj | 36 ++++++++++----- .../duckstation-qt.vcxproj.filters | 3 +- src/duckstation-qt/main.cpp | 44 +++++++++++++++++++ src/duckstation-qt/mainwindow.cpp | 7 ++- src/duckstation-qt/qtdisplaywidget.cpp | 5 ++- src/duckstation-qt/qthostinterface.cpp | 1 + src/duckstation-qt/qthostinterface.h | 4 +- src/duckstation-qt/qtutils.cpp | 2 +- src/duckstation-qt/settingwidgetbinder.h | 12 ++++- 10 files changed, 96 insertions(+), 20 deletions(-) diff --git a/src/duckstation-qt/autoupdaterdialog.cpp b/src/duckstation-qt/autoupdaterdialog.cpp index 8dfd5e75b..8318d7449 100644 --- a/src/duckstation-qt/autoupdaterdialog.cpp +++ b/src/duckstation-qt/autoupdaterdialog.cpp @@ -354,7 +354,9 @@ void AutoUpdaterDialog::downloadUpdateClicked() { QUrl url(m_download_url); QNetworkRequest request(url); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); +#endif QNetworkReply* reply = m_network_access_mgr->get(request); QProgressDialog progress(tr("Downloading %1...").arg(m_download_url), tr("Cancel"), 0, 1); diff --git a/src/duckstation-qt/duckstation-qt.vcxproj b/src/duckstation-qt/duckstation-qt.vcxproj index 81763020d..07140efce 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj +++ b/src/duckstation-qt/duckstation-qt.vcxproj @@ -563,8 +563,9 @@ Windows true $(SolutionDir)dep\msvc\lib32-debug;$(SolutionDir)dep\msvc\qt5-x86\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) + @@ -585,8 +586,9 @@ Windows true $(SolutionDir)dep\msvc\lib64-debug;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) + @@ -607,8 +609,9 @@ Windows true $(SolutionDir)dep\msvc\lib64-debug;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) + @@ -631,8 +634,9 @@ Windows true $(SolutionDir)dep\msvc\lib32-debug;$(SolutionDir)dep\msvc\qt5-x86\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;d3d11.lib;dxgi.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) + @@ -655,8 +659,9 @@ Windows true $(SolutionDir)dep\msvc\lib64-debug;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;d3d11.lib;dxgi.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) + @@ -679,8 +684,9 @@ Windows true $(SolutionDir)dep\msvc\lib64-debug;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;qtmain.lib;d3d11.lib;dxgi.lib;%(AdditionalDependencies) + d3d11.lib;dxgi.lib;%(AdditionalDependencies) + @@ -702,9 +708,10 @@ true true $(SolutionDir)dep\msvc\lib32;$(SolutionDir)dep\msvc\qt5-x86\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) Default + @@ -727,9 +734,10 @@ true true $(SolutionDir)dep\msvc\lib32;$(SolutionDir)dep\msvc\qt5-x86\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) UseLinkTimeCodeGeneration + @@ -751,9 +759,10 @@ true true $(SolutionDir)dep\msvc\lib64;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) Default + @@ -775,9 +784,10 @@ true true $(SolutionDir)dep\msvc\lib64;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) Default + @@ -800,9 +810,10 @@ true true $(SolutionDir)dep\msvc\lib64;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) UseLinkTimeCodeGeneration + @@ -825,9 +836,10 @@ true true $(SolutionDir)dep\msvc\lib64;$(SolutionDir)dep\msvc\qt5-x64\lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5Network.lib;qtmain.lib;dxgi.lib;d3d11.lib;%(AdditionalDependencies) + dxgi.lib;d3d11.lib;%(AdditionalDependencies) UseLinkTimeCodeGeneration + diff --git a/src/duckstation-qt/duckstation-qt.vcxproj.filters b/src/duckstation-qt/duckstation-qt.vcxproj.filters index 44508bf61..a8174d012 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj.filters +++ b/src/duckstation-qt/duckstation-qt.vcxproj.filters @@ -82,6 +82,7 @@ + @@ -220,4 +221,4 @@ translations - \ No newline at end of file + diff --git a/src/duckstation-qt/main.cpp b/src/duckstation-qt/main.cpp index fa7308853..1d6ef5794 100644 --- a/src/duckstation-qt/main.cpp +++ b/src/duckstation-qt/main.cpp @@ -63,10 +63,12 @@ int main(int argc, char* argv[]) qRegisterMetaType>(); qRegisterMetaType>(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); +#endif #endif QApplication app(argc, argv); @@ -114,3 +116,45 @@ int main(int argc, char* argv[]) host_interface->Shutdown(); return result; } + +#ifdef _WIN32 + +// Apparently Qt6 got rid of this? +#include "common/windows_headers.h" +#include + +/* + WinMain() - Initializes Windows and calls user's startup function main(). + NOTE: WinMain() won't be called if the application was linked as a "console" + application. +*/ + +// Convert a wchar_t to char string, equivalent to QString::toLocal8Bit() +// when passed CP_ACP. +static inline char* wideToMulti(unsigned int codePage, const wchar_t* aw) +{ + const int required = WideCharToMultiByte(codePage, 0, aw, -1, nullptr, 0, nullptr, nullptr); + char* result = new char[required]; + WideCharToMultiByte(codePage, 0, aw, -1, result, required, nullptr, nullptr); + return result; +} + +extern "C" int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR /*cmdParamarg*/, int /* cmdShow */) +{ + int argc = 0; + wchar_t** argvW = CommandLineToArgvW(GetCommandLineW(), &argc); + if (argvW == nullptr) + return -1; + char** argv = new char* [argc + 1]; + for (int i = 0; i != argc; ++i) + argv[i] = wideToMulti(CP_ACP, argvW[i]); + argv[argc] = nullptr; + LocalFree(argvW); + const int exitCode = main(argc, argv); + for (int i = 0; (i != argc) && (argv[i] != nullptr); ++i) + delete[] argv[i]; + delete[] argv; + return exitCode; +} + +#endif \ No newline at end of file diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index d80f7c3a5..9f928da19 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -26,12 +26,17 @@ #include #include #include -#include #include #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else +#include +#endif + static constexpr char DISC_IMAGE_FILTER[] = QT_TRANSLATE_NOOP( "MainWindow", "All File Types (*.bin *.img *.iso *.cue *.chd *.ecm *.mds *.pbp *.exe *.psexe *.psf *.minipsf *.m3u);;Single-Track " diff --git a/src/duckstation-qt/qtdisplaywidget.cpp b/src/duckstation-qt/qtdisplaywidget.cpp index 0a2b29c06..78d997a8b 100644 --- a/src/duckstation-qt/qtdisplaywidget.cpp +++ b/src/duckstation-qt/qtdisplaywidget.cpp @@ -144,8 +144,9 @@ bool QtDisplayWidget::event(QEvent* event) if (!m_relative_mouse_enabled) { const qreal dpr = devicePixelRatioFromScreen(); - const int scaled_x = static_cast(static_cast(mouse_event->x()) * dpr); - const int scaled_y = static_cast(static_cast(mouse_event->y()) * dpr); + const QPoint mouse_pos = mouse_event->pos(); + const int scaled_x = static_cast(static_cast(mouse_pos.x()) * dpr); + const int scaled_y = static_cast(static_cast(mouse_pos.y()) * dpr); windowMouseMoveEvent(scaled_x, scaled_y); } diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index e228170e7..d8226d6e5 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -53,6 +53,7 @@ Log_SetChannel(QtHostInterface); QtHostInterface::QtHostInterface(QObject* parent) : QObject(parent), CommonHostInterface() { qRegisterMetaType>(); + qRegisterMetaType(); qRegisterMetaType(); } diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index c9b3c33a3..844d52743 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -3,6 +3,7 @@ #include "core/host_interface.h" #include "core/system.h" #include "frontend-common/common_host_interface.h" +#include "frontend-common/game_list.h" #include "qtutils.h" #include #include @@ -26,14 +27,13 @@ class QWidget; class QTimer; class QTranslator; -class GameList; -struct GameListEntry; class INISettingsInterface; class MainWindow; class QtDisplayWidget; Q_DECLARE_METATYPE(std::shared_ptr); +Q_DECLARE_METATYPE(const GameListEntry*); Q_DECLARE_METATYPE(GPURenderer); class QtHostInterface final : public QObject, public CommonHostInterface diff --git a/src/duckstation-qt/qtutils.cpp b/src/duckstation-qt/qtutils.cpp index 4675377df..4d014b5b7 100644 --- a/src/duckstation-qt/qtutils.cpp +++ b/src/duckstation-qt/qtutils.cpp @@ -756,7 +756,7 @@ std::optional PromptForAddress(QWidget* parent, const QString& title, bool ok; uint address; if (address_str.startsWith("0x")) - address = address_str.midRef(2).toUInt(&ok, 16); + address = address_str.mid(2).toUInt(&ok, 16); else address = address_str.toUInt(&ok, 16); if (code) diff --git a/src/duckstation-qt/settingwidgetbinder.h b/src/duckstation-qt/settingwidgetbinder.h index 799208562..63dd05d13 100644 --- a/src/duckstation-qt/settingwidgetbinder.h +++ b/src/duckstation-qt/settingwidgetbinder.h @@ -5,7 +5,12 @@ #include "core/settings.h" #include "qthostinterface.h" +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#endif + #include #include #include @@ -62,7 +67,7 @@ struct SettingAccessor template<> struct SettingAccessor { - static bool getBoolValue(const QComboBox* widget) { return widget->currentText() > 0; } + static bool getBoolValue(const QComboBox* widget) { return widget->currentIndex() > 0; } static void setBoolValue(QComboBox* widget, bool value) { widget->setCurrentIndex(value ? 1 : 0); } static int getIntValue(const QComboBox* widget) { return widget->currentIndex(); } @@ -74,8 +79,13 @@ struct SettingAccessor static QString getStringValue(const QComboBox* widget) { const QVariant currentData(widget->currentData()); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (currentData.type() == QVariant::String) return currentData.toString(); +#else + if (currentData.metaType().id() == QMetaType::QString) + return currentData.toString(); +#endif return widget->currentText(); }