Re: [Development] Override toString() method for c++ QObject types in QML
That's fine. I was curious if this was possible or not in the current state of QML2. I do not yet have critical need for it but it could also be useful for overriding the valueOf prototype. I will just use another method to provide debug information about a QObject type. Thanks for the quick answer, Luke On 9 November 2015 at 09:10, Knoll Lars wrote: > > On 08/11/15 22:57, "Development on behalf of Stephen Kelly" < > development-boun...@qt-project.org on behalf of steve...@gmail.com> wrote: > > >Konstantin Ritt wrote: > > > >> Maybe JSON.stringify(obj) is what you need? > >> > > > >I think the intention is to override what that does using a specified > >method. > > JSON.stringify() does something slightly different than what you can do by > reimplementing toString(). > > For toString(), the default implementation for the object prototype will > currently get used. Implementing an invokable method on the wrapped QObject > would be nice, but currently there is some logic in the engine missing that > would allow that method to get picked up automatically. > > Cheers, > Lars > > > ___ > Development mailing list > Development@qt-project.org > http://lists.qt-project.org/mailman/listinfo/development > ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
[Development] Override toString() method for c++ QObject types in QML
Is it possible to override the toString method for native c++ QObject types for use in QML scripts? e.g. using Q_INVOKABLE QString toString() const; This doesn't appear to work because it is overridden by some default implementation which returns a pointer value. Is this done intentionally? Could a workaround be done through javascript prototype methods... It would just improve the readability of debug messages and errors when running scripts. Huge Thanks, Luke Parry ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
Re: [Development] C++ QML Interface thoughts
Hi Bo, Thank you for your advice. I think one fault lies is my confidence of whether QML is right for the job due to my inexperience. Currently my GUI is QML which is fantastic but I'm still unsure on the best approach I will take for the backend. The motivation for the question is justifying the long term design, such as potentially supporting other language bindings, user defined scripting / implementations.One case study that made me think of using this approach, is from a talk at Dev Days 2012 for Ipo.Plan (https://www.youtube.com/watch?v=kvWeE3kurEQ) I know my reply isn't technical but perhaps someone knows a good resource that may help? Also, would you be happy to send a pdf of your slides from the talk you held Qt Dev Days? Huge Thanks, Luke On 7 January 2015 at 12:17, Bo Thorsen wrote: > Den 06-01-2015 kl. 12:47 skrev Luke Parry: > > I am having issues trying to implement a c++ qml interface/wrapper that > > supports virtual overrides. Something functionally similar to > > boost::python would be excellent. > > > > This should be generic enough to also support non-QObject classes too so > > it rules out signals and slots. On first glance, it is fairly trivial to > > implement a wrapper that calls methods for the pointer, however > > implementing virtual overrides soon becomes difficult. > > > > I want to achieve something like this ( http://pastebin.com/t3k957Hf ) > > In principle, this would work creating instances in QML but not the > > other way transforming from a c++ instance. > > > > Is this feasible with QML without some compromise? I would like to > > think I'm missing something subtle or something blatantly obvious. > > Sounds to me like you're basically recreating the QObject based > connection between QML and C++ without using QObject. > > That seems silly to me. If you're going to do this, accept that you're > using QObject based subobjects and then you don't need to do this at all. > > Anyway, if you insist on doing this, the trick would probably be to make > the QObject wrapper object have a pointer to the real non-QObject > object. Use aggregation instead of inheritance. > > Bo Thorsen, > Director, Viking Software. > > -- > Viking Software > Qt and C++ developers for hire > http://www.vikingsoft.eu > ___ > Development mailing list > Development@qt-project.org > http://lists.qt-project.org/mailman/listinfo/development > ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development
[Development] C++ QML Interface thoughts
I am having issues trying to implement a c++ qml interface/wrapper that supports virtual overrides. Something functionally similar to boost::python would be excellent. This should be generic enough to also support non-QObject classes too so it rules out signals and slots. On first glance, it is fairly trivial to implement a wrapper that calls methods for the pointer, however implementing virtual overrides soon becomes difficult. I want to achieve something like this ( http://pastebin.com/t3k957Hf ) In principle, this would work creating instances in QML but not the other way transforming from a c++ instance. Is this feasible with QML without some compromise? I would like to think I'm missing something subtle or something blatantly obvious. Huge Thanks Luke Parry ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development