New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gui: PythonWrapper::fromQAction #12577
Conversation
This is an attempt to implement #12542 (comment) |
It's special for the same reason as fromQAction because QPrinter is part of the module QtPrintSupport. However, there is a bug in fromQPrinter where it does Currently, the application also crashes inside Furthermore, QPrinter does not inherit from QObject so that fromQObject isn't an option. And if FreeCAD is built by linking the C++ API of PySide we must have a special converter function, too. |
Thanks for explanation, I'll fix that along the way. However, main concern was following code:
No other wrapper has this special handling, so other could be probably coalesced using template. Let's implement only 1. from #12542 (comment) and leave 2. for separate PR. |
It's probably even better to directly write "QAction" because if there is a sub-class in FreeCAD the method will fail to create a wrapper. |
Indeed, I'll clean that. |
c7f6c2b
to
e67db95
Compare
Contrary to the previous statement, #12542 (comment) is implemented here as well, with other minor changes. These might be easily dropped if they are causing troubles or are just plain wrong. |
@wwmayer this seems fine to me now, but I leave it to your final review. |
The first three commits look OK but as explained in the review the last commit is problematic. And what I still miss is the fix of qt_wrapInstance. I am going to create a new PR based on this one. |
Do you mean |
Yes.
As it was it still caused a segmentation fault because in Qt5 the class QAction is not part of QtGui but QtWidgets. But as we agreed to throw an exception I changed it to return immediately and let the calling instance handle the exception. See 28d9392 |
Ah! I didn't test Qt5 without PySide, sorry. Now it makes sense, thank you. However, I'd rather see another something like |
...as shown in this update. Btw, |
What has been updated? To me it looks like you simply rebased the branch and added my additional commit but left your problematic last commit.
Yes, a similar check can be added there, too. |
I'm sorry, what exactly is the problem with 663c9ba ? At least I do not remember it was mentioned previously. In case you are talking about first commit, 45e9205 I squashed and modified your #ifdef part from your additional commit inside it. |
Because it's a new problem added with this commit. I wonder whether you couldn't see the review comment I have added. Anyway, I explain it again.
The problem is that the output of typeid().name() is not standardized and thus not portable. For different compilers the output string can be different. Some compilers will return "QIcon" but some other compilers will return "class QIcon". But for the qt_wrapInstance() method it is essential to pass the exact class name because it's used to search for the attribute of the given module. E.g. the QtGui module has an attribute Remark: |
No, I haven't see any review comment even after being now notified about it. Knowing about it, I would of course fix that. |
5f75a67
to
b56549c
Compare
Now I get some build failures. If for Qt5 HAVE_PYSIDE2 is not defined then it says: Then I get a further failure with Qt6 which says that the class declaration of QAction cannot be found. Adding |
That would introduce another build failure as code which needs it is
I'll just return back your original solution assuming it was tested with all combinations, so I do not block this PR from merging. |
OK. In a subsequent PR the ifdef hell could be simplified a bit in two steps. For some combinations of HAVE_SHIBOKEN and HAVE_PYSIDE this will generate warnings that an identifier is declared but not used. This can be fixed in the second step by using Q_UNUSED() in the corresponding functions. Edit:
|
Wrapping QAction through QObject does not work as QAction class is a part of QtGui not QtCore, so Py::Object with internal pointer being null is returned causing a crash later. Therefore implement fromQAction conversion method.
When qt_wrapInstance fails it returns Py::Object with internal pointer set to null. Make PythonWrapper::from* methods raise exception when this happens to be consistent with PySide code path.
Handle gracefully possible shiboken's Python API changes.
Use typeName consistently for both PySide and Python interface code paths.
When writing adaptation for different extensions, people write something like that: void func (void)
{
#ifdef SSE
func_SSE();
#endif
#ifdef SSE2
func_SSE2();
#endif
#ifdef AVX
func_AVX();
#endif
#ifdef AVX2
func_AVX2();
#endif
}
Perhaps, it would be better to recompartmentalize in this fashion. I would also add that these implementations can be put into different files, like |
shiboken or PySide stuff shouldn't be visible in any header file to avoid to make other source files depending on it. That's why all this stuff is in a single source file. Theoretically, we could have different source files for shiboken2/PySide2 and shiboken6/PySide6 but then we will end up in a lot of code duplication. The real differences between these two versions are less than 20 lines of code. |
No description provided.