Qt: Support Qt 6
This commit is contained in:
@ -63,10 +63,12 @@ int main(int argc, char* argv[])
|
||||
qRegisterMetaType<std::optional<bool>>();
|
||||
qRegisterMetaType<std::function<void()>>();
|
||||
|
||||
#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 <shellapi.h>
|
||||
|
||||
/*
|
||||
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
|
||||
Reference in New Issue
Block a user