diff --git a/src/Tools/embedded/Qt/Qt.pro b/src/Tools/embedded/Qt/Qt.pro index 79ea029b5fb0..8d1f508e0797 100644 --- a/src/Tools/embedded/Qt/Qt.pro +++ b/src/Tools/embedded/Qt/Qt.pro @@ -1,12 +1,26 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Di 15. Mrz 12:13:51 2011 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += mainwindow.h -SOURCES += main.cpp mainwindow.cpp + +TEMPLATE = app +TARGET = Qt +INCLUDEPATH += . + +linux { + INCLUDEPATH += /usr/include/python3.6 + LIBS += -lpython3.6m +} + +QT += widgets + +# The following define makes your compiler warn you if you use any +# feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Input +HEADERS += mainwindow.h +SOURCES += main.cpp mainwindow.cpp diff --git a/src/Tools/embedded/Qt/main.cpp b/src/Tools/embedded/Qt/main.cpp index cfc0df94fffd..f00a5adfdcd2 100644 --- a/src/Tools/embedded/Qt/main.cpp +++ b/src/Tools/embedded/Qt/main.cpp @@ -1,15 +1,21 @@ -#include +#include #include #include "mainwindow.h" int main(int argc, char *argv[]) { - char* name = "Qt example"; - Py_SetProgramName(name); + const char* name = "Qt example"; + Py_SetProgramName(Py_DecodeLocale(name,NULL)); Py_Initialize(); - PySys_SetArgv(argc, argv); + + size_t size = argc; + wchar_t **_argv = new wchar_t*[size]; + for (int i = 0; i < argc; i++) { + _argv[i] = Py_DecodeLocale(argv[i],NULL); + } + PySys_SetArgv(argc, _argv); QApplication app(argc, argv); MainWindow mainWin; diff --git a/src/Tools/embedded/Qt/mainwindow.cpp b/src/Tools/embedded/Qt/mainwindow.cpp index 0212ea6f3185..bb66026f17d5 100644 --- a/src/Tools/embedded/Qt/mainwindow.cpp +++ b/src/Tools/embedded/Qt/mainwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #if defined(Q_WS_X11) # include #endif @@ -87,7 +88,7 @@ void MainWindow::loadFreeCAD() PyObject *ptype, *pvalue, *ptrace; PyErr_Fetch(&ptype, &pvalue, &ptrace); PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); + const char* error = PyUnicode_AsUTF8(pystring); QMessageBox::warning(this, "Error", error); Py_DECREF(pystring); } @@ -110,7 +111,7 @@ void MainWindow::newDocument() PyObject *ptype, *pvalue, *ptrace; PyErr_Fetch(&ptype, &pvalue, &ptrace); PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); + const char* error = PyUnicode_AsUTF8(pystring); QMessageBox::warning(this, "Error", error); Py_DECREF(pystring); } @@ -119,7 +120,6 @@ void MainWindow::newDocument() void MainWindow::embedWindow() { - WId hwnd = this->centralWidget()->winId(); PyObject* main = PyImport_AddModule("__main__"); PyObject* dict = PyModule_GetDict(main); std::stringstream cmd; @@ -134,18 +134,41 @@ void MainWindow::embedWindow() << "\n" << "FreeCADGui.addWorkbench(BlankWorkbench)\n" << "FreeCADGui.activateWorkbench(\"BlankWorkbench\")\n" - << "FreeCADGui.embedToWindow(\"" << hwnd << "\")\n" << "\n"; + +#if defined(Q_WS_X11) || defined(Q_OS_WIN) + WId hwnd = this->centralWidget()->winId(); + cmd << "FreeCADGui.embedToWindow(\"" << hwnd << "\")\n" + << "\n"; +#endif + PyObject* result = PyRun_String(cmd.str().c_str(), Py_file_input, dict, dict); if (result) { Py_DECREF(result); + +#if !defined(Q_WS_X11) + // This is a workaround for the lack of a replacement of QX11EmbedWidget with Qt5 + QWidget* mw = nullptr; + for (auto it : qApp->topLevelWidgets()) { + if (it->inherits("Gui::MainWindow")) { + mw = it; + break; + } + } + if (mw) { + QVBoxLayout* vb = new QVBoxLayout(); + centralWidget()->setLayout(vb); + vb->addWidget(mw); + } +#endif + embedAct->setDisabled(true); } else { PyObject *ptype, *pvalue, *ptrace; PyErr_Fetch(&ptype, &pvalue, &ptrace); PyObject* pystring = PyObject_Str(pvalue); - const char* error = PyString_AsString(pystring); + const char* error = PyUnicode_AsUTF8(pystring); QMessageBox::warning(this, "Error", error); Py_DECREF(pystring); }