On Sat, Nov 10, 2012 at 11:35 PM, Robert Voinea <rvoi...@gmail.com> wrote: > > > Hi > > > > On Saturday 10 November 2012 20:05:13 Mark wrote: > >> On Sat, Nov 10, 2012 at 8:03 PM, Robert Voinea <rvoi...@gmail.com> wrote: > >> > I am not saying to instantiate it as QObject, but expose it to qml as > >> > qobject. > >> > > >> > I'm sorry that my replies are so short... but i'm writing from my phone. > >> > > >> > As soon as I get in front of my pc I'll send a more detailed > >> > example/explanation... > >> > > >> > On Nov 10, 2012 8:54 PM, "Mark" <mark...@gmail.com> wrote: > >> >> On Sat, Nov 10, 2012 at 7:47 PM, Robert Voinea <rvoi...@gmail.com> >> >> wrote: > >> >> > This is working for me: > >> >> > > >> >> > instead of > >> >> > Q_INVOKABLE PathModel* pathModel(); > >> >> > Try using > >> >> > Q_INVOKABLE QObject* pathModel(); > >> >> > > >> >> > I believe there was a bug with custom types exported to qml... >> >> > QVariant > >> >> > related... > >> >> > >> >> > On Nov 9, 2012 8:37 PM, "Mark" <mark...@gmail.com> wrote: > >> >> Hi Robert, > >> >> > >> >> Could you explain a bit more? I'm actually using QStringListModel > >> >> function inside my Util class. These obviously don't work anymore if i > >> >> instantiate it as a QObject.. > >> >> > >> >> Cheers, > >> >> Mark > >> > >> That would be very nice :) > > > > First of all... the bug I was talking about is this > > https://bugreports.qt-project.org/browse/QTBUG-13047 > > But it seems to be fixed in Qt 4.7.1 > > > > Well... I'd use something like this: > > > > pathmodel.h > > class PathModel : public QStringListModel > > { > > public: > > explicit PathModel(QObject *parent = 0); > > }; > > > > util.h > > > > class Util : public QObject > > { > > Q_OBJECT > > Q_PROPERTY(QObject* pathModel READ pathModel CONSTANT) > > public: > > ... > > PathModel* pathModel() { return &m_pathModel; }; > > Q_INVOKABLE QString testString() { return "some_test_text"; } > > private: > > PathModel m_pathModel; > > }; > > > > with the downside of having to include the header for pathModel. > > > > As far as I know every variable, item, etc in QML is a QVariant. > > > > For QObject-derived classes their properties are exposed to QML and used > through the QObject interface. > > > > > > -- > > Robert Voinea > > IT Specialist > > +4 0740 467 262 > > > > Don't take life too seriously. You'll never get out of it alive. > > (Elbert Hubbard)
Oke, i wasn't expecting that. I added the Q_PROPERTY(QObject* pathModel READ pathModel CONSTANT) stuff to my code (and removed the Q_INVOKABLE from my pathModel method), changed the code to use the new property and amazingly it worked! Why isn't this clearly documented _anywhere_? I certainly can use google and know the Qt docs quite well, but i haven't found anything that would indicate me to do it this way. Another question, how can i get the same stuff working as a function call? Now it works as a Q_PROPERTY which is fine for my case, but i'm just curious about the same for a function call. Cheers, Mark _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest