Skip to content

Commit 9f0f06e

Browse files
committed
QT, Win32: The QT GUI now compiles on Windows and loading/saving works...
Fix compilation on Windows QT5: Compiles and works, but the property browser window is broken. QT6: Compiles but crashes. Fix file opening and saving on Windows by using `QDir::toNativeSeparators()` in `Platform::Path GetFilename()` to retrieve the path returned by `QFileDialog` in a platform-independent way and normalize the file separators (`/` for Unix-like platforms and `\` for Windows). Here’s how the returned path differs by platform: 1. **Unix/Linux/macOS**: - File path: `"/home/user/example/file.slvs"` - Result of `QDir::toNativeSeparators()`: `"/home/user/example/file.slvs"` 2. **Windows**: - File path: `"C:/Users/user/example/file.slvs"` - Result of `QDir::toNativeSeparators()`: `"C:\Users\user\example\file.slvs"`
1 parent ac932ab commit 9f0f06e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/platform/guiqt.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <QSettings>
2828
#include <QTimer>
2929

30+
#if WIN32
31+
# include <windows.h>
32+
#endif
3033

3134
namespace SolveSpace {
3235
namespace Platform {
@@ -159,7 +162,7 @@ class FileDialogImplQt final : public FileDialog {
159162

160163
Platform::Path GetFilename() {
161164
QStringList files = fileDialogQ.selectedFiles();
162-
return Path::From(files.at(0).toStdString());
165+
return Path::From(QDir::toNativeSeparators(files[0]).toStdString());
163166
}
164167

165168
void SetFilename(Platform::Path path) {
@@ -935,6 +938,11 @@ class WindowImplQt final : public Window {
935938
}
936939
};
937940

941+
#if defined(WIN32)
942+
// This interferes with our identifier.
943+
# undef CreateWindow
944+
#endif
945+
938946
WindowRef CreateWindow(Window::Kind kind, WindowRef parentWindow) {
939947
return std::make_shared<WindowImplQt>(kind,
940948
std::static_pointer_cast<WindowImplQt>(parentWindow));
@@ -968,7 +976,6 @@ void Request3DConnexionEventsForWindow(WindowRef window) {}
968976
//-----------------------------------------------------------------------------
969977
// Application-wide APIs
970978
//-----------------------------------------------------------------------------
971-
972979
std::vector<Platform::Path> GetFontFiles() {
973980
#if WIN32
974981
std::vector<Platform::Path> fonts;
@@ -1044,6 +1051,8 @@ int main(int argc, char** argv) {
10441051
// See https://bugreports.qt.io/browse/QTBUG-89812
10451052
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
10461053

1054+
1055+
#ifndef WIN32 // Allows using OpenGL 1 on Windows
10471056
// Specify the GL version so Qt doesn't use GLES on Wayland, which
10481057
// doesn't handle "#version 120" shaders.
10491058
{
@@ -1053,6 +1062,7 @@ int main(int argc, char** argv) {
10531062
fmt.setProfile(QSurfaceFormat::CoreProfile);
10541063
QSurfaceFormat::setDefaultFormat(fmt);
10551064
}
1065+
#endif
10561066

10571067
Platform::SSApplication app(argc, argv);
10581068
Platform::Open3DConnexion();

0 commit comments

Comments
 (0)