Menu

how to handle interface

Help
Tonka
2016-09-19
2016-09-21
  • Tonka

    Tonka - 2016-09-19

    Hey,

    i've try to use the generator to generate a shell-class for a class which has partial pure virtual functions

    f.e.

    class MyClass
    {
        virtual void foo() = 0;
        virtual QString name() const;
    }
    

    My problem: If i use

    <object-type name="MyClass"></object-type>
    

    i can generate the cpp code, but i can not compile it because i get the error

    'PythonQtShell_MyClass' : cannot instantiate abstract class
    

    I know what that mean but i don't know how i can add something to the typesystem-xml file, that will tell the generator that this class is not instantiable.

    Can anybody give my some hint?

    Thanks in advance
    Tonka

     
  • Florian Link

    Florian Link - 2016-09-20

    Are your methods really private, or did you skip something? I think the abstract virtual functions need to be public or protected.

     
  • Tonka

    Tonka - 2016-09-20

    Ups, all methods are public, i've forget that line in my example.
    Do you have a solution for my problem?

     
  • Florian Link

    Florian Link - 2016-09-21

    Well, PythonQt supports this and should automatically reimplement the abstract methods so that the shell class becomes creatable. Try reducing the number of abstract methods to a simple example and see if that works. I suspect that you have an abstract method that uses unknown types in its parameters. You can also have a look at the rejected methods (this is a text file that the generator creates), it will list all methods that were not wrapped.

     
  • Tonka

    Tonka - 2016-09-21

    I've check the rejected methods file and i've see that there are some rejected methods. All rejected functions contains a std::unique_ptr<> (C++ 11) in the signature or in the return value.

    examples:
    std::unique_ptr remove(int iIndex);
    void add(std::unique_tr<MyClass>);

    the class (in my example MyClass) from std::unqiue_ptr is know by the typesystem and is not rejected and has no rejected methods.

    Can i add std::unique_ptr to the typesystem?

    Could it be that PythonQt generator could not handle std::unique_ptr that? If yes, is there any possiblity to get that working with the generator (by hand would be horrible, because i have hundreds of class with std::unique_ptr)?

     
  • Florian Link

    Florian Link - 2016-09-21

    PythonQt does not support std::unique_ptr and this can not be added easily, since the semantics of std::unique_ptr would require that PythonQt holds the returned object as a std::unique_ptr, but PythonQt holds a normal pointer internally.

     
  • Tonka

    Tonka - 2016-09-21

    Oh, so there nothing i can do?
    Technically it should be possible (you can make a ), but the actual generator could not handle that - is that correct?
    Is this a problem from the Qt Jambi code?

    It should be possible to generate a Wrapper class per template type f.e.

    std::unique_ptr<MyClass> could get a wrapper class called f.e. MyClass_unique_ptr which only handle the std::unique_ptr itself, so the script engine gets these wrapper class. These soloution could work for most templates. Do you see any change to get this working with the QtJambi code?

     
  • Florian Link

    Florian Link - 2016-09-21

    No, I don't see how that could be done.

     
  • Tonka

    Tonka - 2016-09-21

    I will tinker a little bit and try to validate if could do that.

    Do you accept patches? Is there any git repo (like guthub) instead of svn, because it would be much easier to support your project?

     
  • Florian Link

    Florian Link - 2016-09-21

    Nope, only svn, sorry. I accept patches.

     

Log in to post a comment.