Menu

Using the generator.

2009-09-06
2015-05-25
  • Dallin Wellington

    I was wondering how I might go about using the generator to generate bindings for my classes. I know you do have to write your own typesystem files, but that doesnt seem to be everything you need to do. Any help?

     
  • Florian Link

    Florian Link - 2009-09-20

    The generator is an adapted generator of QtJambi, if you have a look at

    http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/qtjambi-generatorexample.html

    it should give you a start. The important thing is that your own typesystem files need to include the qt typsesystems (which are included in the generator) and set the generate code flag to false (see the QtJambi example).
    You need to generate you own header file which includes all classes that you want to wrap. Afterwards you need to list all those classes in you typesystem (which classes are found can be seen in the log files of the generator).

     
  • Dallin Wellington

    Hi,
    Thanks for that reference. it is helping a ton.

    However, I was wondering if there was a problem with handing over ownership of an object from python to c++? I cant seem to get it to work, and it is causing my program to crash because pythons GC is grabbing it after I leave the scope of the function.

     
  • Erik Lundin

    Erik Lundin - 2015-01-28

    When I build with Python 2.7 and Qt 5 on Linux Mint 17.1, the linker is missing PythonQt_init_QtMultimedia, which seems to be because there is no com_trolltech_qt_multimedia folder in generated_cpp_50 (there is one in generated_cpp_53). However I don't know how to generate those files (pythonqt_generator seems to be one part of it, but I haven't been able to run it with the right arguments).

     
  • Florian Link

    Florian Link - 2015-01-28

    You should not need any arguments to run the generator.

    You might need to set QTDIR to point to your QT installation, the generator logs which Qt version it is using.

    After running the generator, it will generate the directory

    generated_cpp

    (without Qt version number).

    After this, you need to re-create your make files from the supplied profiles, this will detect the 'generated_cpp' directory and use it instead of genrated_cpp50.

    Alternatively you can just uncomment the Qt Multimedia references in the PythoQtAll project and source (if you don't need the Qt Multimedia package).

     
  • Henry Choi

    Henry Choi - 2015-05-24

    Dear Florian, thank you for this contribution to the Qt community. I just cross compiled PythonQt3.0 for ARM7tdmi and ran the test, but got 1 failure

    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() "Traceback (most recent call last):
    "
    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() " File "<string>", line 1, in <module>
    "
    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() "ValueError"
    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() ": "
    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() "Called getChar(char a) -> char with wrong argume
    nts: (-12,)"
    QDEBUG : PythonQtTestSlotCalling::testPODSlotCalls() "
    "
    FAIL! : PythonQtTestSlotCalling::testPODSlotCalls() '_helper->runScript("if obj.getChar(-12)==-12: ob
    j.setPassed();\n")' returned FALSE. ()
    Loc: [PythonQtTests.cpp(188)]

    I had to modify the file pyport.h line 814 (change #error to #warning) to work around the LONG_BIT problem, and comment out any code related to the Qt modules I did not pull in for my embedded target (such as OpenGL and uitool). I wonder if the above failure is due to that?

    I realize that it would be better to generate the wrapper codes that are customized to my embedded Qt (which is generated by Buildroot 2015.02), but I could not figure out how to use pythonqt_generator to generate the code. I tried copying the generator/ folder to my target (because the generator subfolder cross-compiles cleanly), but there is no code produced, because I think there is no qmake for my embedded target. Buildroot generated qmake is on the development host. I saw another discussion where someone ran the pythonqt_generator on his Anstrom target, but I don't understand how that is possible--unless qmake is on the target. In MY case, I believe we should use the qmake that was specifically generated for my Buildroot distribution, but I cannot figure out how to tell that to pythonqt_generator.

    Perhaps another option is to just run the x64 version (my regular) of the pythonqt_generator, but point it at the qmake built by Buildroot for my ARM target? Do you have any suggestion please?

    Thank you very much for reading.
    -Henry

     
    • Florian Link

      Florian Link - 2015-05-25

      If you set the environment variable QTDIR to point to the Qt version that you want to wrap and then run the generator, it should create the cpp wrappers for that version. It does not matter with which version of Qt the generator was built, only the header files that it finds when it is started matter. Qmake is only needed for the build step, not the generator.

      Regarding the failed test, it sounds like the conversion from Python to char is broken, I have no idea why. There are not many Api calls that take char in the Qt Api, so it is probably not a big deal. Otherwise, I would suggest stepping into the test with the debugger to see what goes wrong.

      Regards,
      Florian

       

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.