Menu

QSocketNotifier not wrapped for Qt5

2018-02-04
2018-02-12
  • Steve Pieper

    Steve Pieper - 2018-02-04

    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:

    >>> qsn = qt.QSocketNotifier()
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    ValueError: No constructors available for QSocketNotifier
    

    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!).

     
  • Florian Link

    Florian Link - 2018-02-05

    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

    #include <QtSocketNotifier>
    

    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.

     
  • Florian Link

    Florian Link - 2018-02-06

    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.

     
  • Steve Pieper

    Steve Pieper - 2018-02-06

    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.

     
  • Steve Pieper

    Steve Pieper - 2018-02-06

    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?

     
  • Florian Link

    Florian Link - 2018-02-06

    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.

     
  • Steve Pieper

    Steve Pieper - 2018-02-06

    Sounds good. I can try some experiments in our fork and send you the diffs.

     
  • Florian Link

    Florian Link - 2018-02-06

    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?

     
  • Steve Pieper

    Steve Pieper - 2018-02-06

    I call it the result of fileno() on python socket object. The python docs say this is "a small integer".

     
  • Florian Link

    Florian Link - 2018-02-06

    Ok, I think we need to add it to the type aliases, I will give you details tomorrow at work.

     
  • Florian Link

    Florian Link - 2018-02-07

    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?

     
  • Florian Link

    Florian Link - 2018-02-07

    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.

     
  • Steve Pieper

    Steve Pieper - 2018-02-07

    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:

      File "/Users/pieper/slicer4/latest/SlicerWeb/WebServer/WebServer.py", line 1841, in start
        self.notifier = qt.QSocketNotifier(self.socket.fileno(),qt.QSocketNotifier.Read)
    ValueError: Could not find matching overload for given arguments:
    (22, 0)
     The following slots are available:
    QSocketNotifier(qintptr socket, QSocketNotifier::Type arg__2, QObject parent) -> QSocketNotifier
    QSocketNotifier(qintptr socket, QSocketNotifier::Type arg__2) -> QSocketNotifier
    
     
  • Steve Pieper

    Steve Pieper - 2018-02-07

    Oops, sorry - my mistake: I forgot to include the patch to PythonQtMethodInfo.cpp. With that it's working!

     
  • Florian Link

    Florian Link - 2018-02-07

    Great, thanks for the update!

     
  • Steve Pieper

    Steve Pieper - 2018-02-07

    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!

     
  • Florian Link

    Florian Link - 2018-02-09

    I will update the 5.6 wrappers next Monday, I will not update the older wrappers.

     
  • Florian Link

    Florian Link - 2018-02-12

    I just commited the regenerated wrappers for Qt 5.6

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.