QSocketNotifier not wrapped for Qt5
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi -
We are in the process of switching from Qt 4.8 to Qt 5.10 for our app and most things work fine, but I recently noticed that QSocketNotifier is not available.
Error is:
I was able to manually work around this by copying over the generated code from the older Qt version (see diff in link below) but I wonder if anyone knows how to fix this in the generator itself?
https://github.com/commontk/PythonQt/pull/63
-Steve
(p.s. Thanks again for PythonQt!).
This is really strange, we work with Qt 5.6 and the wrappers look fine. I compared the header files of qsocketnotifier.h (5.6 and 5.10) and they are identical except for the license header.
Maybe QSocketNotifier is no longer included when one includes QtCore/QtCore and thus the generator does not see it?
Try adding
to qtscript_masterinclude.h and rebuild and rerun the generator.
You can also have a look at the generated .preprocessed.tmp file, which is basically everything that the generator will parse. If that file contains the QSocketNotifier header, then the generation should work. If it is not in there, the generator will not see it.
Hi Florian -
It is indeed strange - everything else I've tried seems work fine. Maybe I'm the only one who used QSocketNotifier from PythonQt.
If you look at the generated code from 4.8 in [1] it has the constructors and all the methods while the while the ones for 5.0 [2] only three methods. So the class is not completely skipped but it is incomplete for some reason.
I agree the Qt headers look essentially the same so I suppose something happened in the generator process. In my workaround I copy the QSocketNotifier block from the 4.8 version into the 5.0 version and rebuild PythonQt and it works as expected.
Can you let me know how to run the generator? (or point to docs - I didn't find any info on the web site or in the code). I was able to build it with the change you suggested.
Best regards,
Steve
[1] https://sourceforge.net/p/pythonqt/code/HEAD/tree/branches/Qt4LastWorkingVersion/generated_cpp_48/com_trolltech_qt_core/com_trolltech_qt_core1.cpp#l4274
[2] https://sourceforge.net/p/pythonqt/code/HEAD/tree/trunk/generated_cpp_50/com_trolltech_qt_core/com_trolltech_qt_core2.cpp#l1423
[3] https://sourceforge.net/p/pythonqt/code/HEAD/tree/trunk/generated_cpp_56/com_trolltech_qt_core/com_trolltech_qt_core2.cpp#l4545
Just run pythonqt_generator executable inside of the generator subdir. If it does not find your Qt version, set QTDIR environment variable to point to it before running the generator.
I noticed that the Qt 5.6 QSocketNotifier wrappers already miss the constructor, so they are not really functional in 5.6 wrappers either.
I will see if I find some time to step through the generator to see what goes wrong.
Thanks Florian. I was able to run the generator with this command:
$ QTDIR=~/Qt/5.8/gcc_64/ ./pythonqt_generator
$ grep QSocketNotifier *.log mjb_rejected_functions.log:QSocketNotifier::d_func mjb_rejected_functions.log:QSocketNotifier::QSocketNotifier qintptr mjb_rejected_functions.log:QSocketNotifier::socket qintptr
It looks like qintptr is not in the type system? There are a bunch of other socket-related classes listed in the rejected function log.
Okay, I guess I figured it out - adding this
<primitive-type name="qintptr"/>
to the end of line 168 of typesystem_core.xml appears to fix the wrapping fpr the socket classes (not tested yet, but the generated code looks like what I expect.
There are many other rejected functions in the log so maybe it would be good to make a pass through and add more types?
That makes sense, the intptr was probably introduced in Qt5.
Yes, it makes sense to look through the rejected functions again, although many are not wrappable or intentionally ignored like the d_ptr/d_func stuff.
Sounds good. I can try some experiments in our fork and send you the diffs.
Thinking about it, we probably need to handle qintptr in the PythonQtConversion.cpp otherwise it will not convert well to/from Python int/long. From where do you typically get the qintptr that you pass to QSocketNotifier?
I call it the result of fileno() on python socket object. The python docs say this is "a small integer".
Ok, I think we need to add it to the type aliases, I will give you details tomorrow at work.
I commited a change on PythonQtMethodInfo.cpp (on SVN trunk) to add support for WId, quintptr and qintptr. The fun thing is that qintptr is ONLY used in QSocketNotifier and quintptr is only used in the model index API, which is why nobody else ran accross this yet.
Do you still need the extra QSocketNotifier include for Qt 5.10 or does it work without the extra include in the master include file?
I looked through the rejected functions, but I did not find anything else that seems important, most are internal Qt things that you don't want to mess with from Python.
Once exception are the QMatrixAxB types, which are used on the QOpenGL classes at some places, but those can't be wrapped easily because they are only typedefs to a template base class, which the generator does not support.
I rebuilt with the current svn trunk of PythonQt. The QSocketNotifier include in qtscript_masterinclude.h was not needed.
Unfortunately the new wrappings don't work for me - the constructor exists but it's not callable with a python integer. Is there a way to cast a python integer to a qintptr?
This is the error message:
Oops, sorry - my mistake: I forgot to include the patch to PythonQtMethodInfo.cpp. With that it's working!
Great, thanks for the update!
What's the next step on your end - will you make a new set of generated_cpp files in svn?
As you know we try to keep the patched fork in CTK as close to your version as possible.
https://github.com/commontk/PythonQt
Thanks again for the fix!
I will update the 5.6 wrappers next Monday, I will not update the older wrappers.
I just commited the regenerated wrappers for Qt 5.6