Menu

possible to add QPointer support?

Help
Anonymous
2010-05-14
2013-04-06
  • Anonymous

    Anonymous - 2010-05-14

    Hi,

    First off, thanks for creating this extremely useful library.

    Is there any chance of handling QPointer ? I have an object model that handles all QObjects as QPointer<T> - as opposed to raw pointer T* - and PythonQT therefore doesn't recognize the given type 'T' that I  register. Note I'm specifically requesting this w.r.t. the dynamic slot-based approach, not the generator (the latter I suppose could be used to wrap my object model?).

    Thanks in advance for any answer!

     
  • Florian Link

    Florian Link - 2010-05-15

    Hm, I am not sure if I understand your right…

    Does your API look like this:

    QPointer<SomeResult> doSomething(QPointer<SomeObject> object)

    and you would like PythonQt to detect the SomeResult / SomeObject types and pass correct QPointers?

    Although this is doable (it would need to be implemented in PythonQtConversion), if this is really your API, I have to admit that I do not understand why you use QPointer in such a way?

    QPointer is a weak pointer that gets NULLified when the QObject is deleted. But there is no reason to pass it around as QPointers, it should be enough to store a QPointer reference inside of your classes. I can see no advantage of passing them around as a QPointer?!

    regards,
    Florian

     
  • Anonymous

    Anonymous - 2010-05-16

    Hi Florian,

    Correct, and that's a good point, thanks. One issue I have is that I have things like QList < QPointer <T > > as members. So in this case it seemed easier for the functions to return that directly vs. converting it to raw pointers first. And after I did that, it just seemed a nicer API to consistently return QPointers for all cases, since I was immediately building them again upon receipt anyway (slippery slope ;-).

    Does that make sense or have I headed off in the wrong direction altogether? In particular, how are QPointer lists generally handled? (And thanks *very much* for any help, I know this is no longer really a PythonQt conversation).

    Thanks again!
    Jason

     
  • Florian Link

    Florian Link - 2010-05-16

    Since a QList of pointers is not very expensive, I would say you should use QList<SomeObject*> instead.

    Regarding QList<QPointer<SomeObject> >, I guess one could get away with using a QList<QPointer<QObject> > implementation,  it should be safe to cast such a QList to the derived QPointer type.

    So you could use the PythonQtConv:: registerMetaTypeToPythonConverter() method to register all
    versions that you want to support. The conversion method would be similiar to what is done in
    PythonQtConvertListOfValueTypeToPythonList (in same file).

    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.