[PyQt] PyQt support for Qt 4.7
Phil Thompson
phil at riverbankcomputing.com
Fri Oct 8 09:06:03 BST 2010
On Fri, 8 Oct 2010 02:44:25 +0200, Andreas Pakulat <apaku at gmx.de> wrote:
> On 08.10.10 01:08:08, Giovanni Bajo wrote:
>> On Thu, 07 Oct 2010 16:34:41 +0100, Phil Thompson
>> <phil at riverbankcomputing.com> wrote:
>> > On Thu, 7 Oct 2010 00:35:16 +0200, David Boddie <david at boddie.org.uk>
>> > wrote:
>> >> On Tue Oct 5 09:36:49 BST 2010, Phil Thompson wrote:
>> >>
>> >>> The minehunt example only seems to need support for lists of
>> >>> QObjects.
>> >>> Are
>> >>> there any other examples anywhere that have different use cases?
>> >>
>> >> I guess that's more or less what it is, though it needs something
>> >> extra
>> > to
>> >> make the QML engine aware of the new TileData type, used as a
property
>> > type
>> >> in the MinehuntGame class, and used as the model that holds the tile
>> > data
>> >> in
>> >> the game. If you can figure out a way to expose homogeneous Python
>> lists
>> > as
>> >> QDeclarativeListProperty containers then that would be cool.
>> >
>> > Done that.
>> >
>> >> Looking through the examples, there are places where qmlRegisterType
>> >> is
>> >> used
>> >> to add C++ classes to QML as new item types. The "Writing QML
>> extensions
>> >> with
>> >> C++" tutorial in examples/declarative/tutorials/extending is one of
>> > these.
>> >
>> > ...and there we hit the showstopper.
>> >
>> > It looks like it is not possible to publish Python types to QML (and
>> > use
>> > the QML import statement) because QML uses a QObject's
staticMetaObject
>> > instead of calling metaObject(). That automatically limits it to
types
>> > known at compile time and no way to inject dynamic meta-objects
created
>> at
>> > run time.
>>
>> I think that's because they need to construct new instances for that
type
>> at runtime. I can't see how an object could be instantiated through a
>> pointer to its QMetaObject instance (let alone a *dynamic* meta
object).
>
> Even though I might just show that I don't have a real clue about what
> you're talking, but how about QMetaObject::newInstance()? At least by
the
> API docs it sounds as that function would allow to create a new instance
> with just a QMetaObject pointer. (as long as Q_INVOKEABLE is used for at
> least 1 constructor).
You don't know the Python type of the instance to create.
What Qt needs is a non-template function that can register QMetaObject
instances created on the heap, a virtual version of
QMetaObject::newInstance(), and virtual non-static versions of
QMetaObject::invokeMethod().
Phil
More information about the PyQt
mailing list