Re: [Interest] Overriding list properties in QML at initialisation

2019-08-14 Thread Unai IRIGOYEN
Ulf,
I reported the bug here: https://bugreports.qt.io/browse/QTBUG-77529

I will try to propose a fix which has no side effect on Qt3D.

Best regards,

Unai

Le mer. 14 août 2019 à 11:25, Ulf Hermann  a écrit :

> Hello,
>
> > If I create a class with a QQmlListProperty and then initialise it with
> > an array in some QML file, then subclass the QML type in a second QML
> > file and try to override the array there, when creating an instance of
> > the child class, the list contains the arrays concatenated instead of
> > the overriding array.
>
> That's the expected behavior of the default property, e.g. children in
> QQuickItem. Arguably, it should not extend to explicitly setting any
> other list properties.
>
> > In the following example, I would expect the list to contain 2 elements
> > instead of 5. What are your thoughts? Should I fill a bug report and try
> > to provide a fix?
>
> Yes, that would be nice. Keep in mind that the default property should
> still behave the old way, but only if you actually use it as default
> property. The details can be discussed in the report, though.
>
> best regards,
> Ulf
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Overriding list properties in QML at initialisation

2019-08-14 Thread Unai IRIGOYEN
Hi Giuseppe,
When you say the QML APIs for Qt3D depend on this behaviour, you are
talking about appending to the default property right? Or are the APIs
depending in the fact that every QQmlListProperty has its contents
concatenated (I can't recall an example where this could be used)?

Best regards,

Unai

Le mer. 14 août 2019 à 18:23, Giuseppe D'Angelo via Interest <
interest@qt-project.org> a écrit :

> Il 14/08/19 11:23, Ulf Hermann ha scritto:
> >> In the following example, I would expect the list to contain 2 elements
> >> instead of 5. What are your thoughts? Should I fill a bug report and try
> >> to provide a fix?
> > Yes, that would be nice. Keep in mind that the default property should
> > still behave the old way, but only if you actually use it as default
> > property. The details can be discussed in the report, though.
>
> This behaviour cannot be changed in a source-compatible way, so it's a
> no-go, unless we also add additional C++/QML syntax for opting in to the
> new behaviour. E.g. the QML APIs for Qt3D massively depend on this.
>
> My 2 c,
> --
> Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
> KDAB (France) S.A.S., a KDAB Group company
> Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
> KDAB - The Qt, C++ and OpenGL Experts
>
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Overriding list properties in QML at initialisation

2019-08-14 Thread Giuseppe D'Angelo via Interest

Il 14/08/19 11:23, Ulf Hermann ha scritto:

In the following example, I would expect the list to contain 2 elements
instead of 5. What are your thoughts? Should I fill a bug report and try
to provide a fix?

Yes, that would be nice. Keep in mind that the default property should
still behave the old way, but only if you actually use it as default
property. The details can be discussed in the report, though.


This behaviour cannot be changed in a source-compatible way, so it's a 
no-go, unless we also add additional C++/QML syntax for opting in to the 
new behaviour. E.g. the QML APIs for Qt3D massively depend on this.


My 2 c,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts



smime.p7s
Description: Firma crittografica S/MIME
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Overriding list properties in QML at initialisation

2019-08-14 Thread Ulf Hermann
Hello,

> If I create a class with a QQmlListProperty and then initialise it with 
> an array in some QML file, then subclass the QML type in a second QML 
> file and try to override the array there, when creating an instance of 
> the child class, the list contains the arrays concatenated instead of 
> the overriding array.

That's the expected behavior of the default property, e.g. children in 
QQuickItem. Arguably, it should not extend to explicitly setting any 
other list properties.

> In the following example, I would expect the list to contain 2 elements 
> instead of 5. What are your thoughts? Should I fill a bug report and try 
> to provide a fix?

Yes, that would be nice. Keep in mind that the default property should 
still behave the old way, but only if you actually use it as default 
property. The details can be discussed in the report, though.

best regards,
Ulf
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] Overriding list properties in QML at initialisation

2019-08-13 Thread Unai IRIGOYEN
Hello,
I'm using QML for some years now but recently I have found a behaviour
which may be a bug or at least makes list property initialisation
inconsistent with the way other types are handled.
The behaviour can be traced back to (at least) Qt 5.2 and is still present
in Qt 5.13.
If I create a class with a QQmlListProperty and then initialise it with an
array in some QML file, then subclass the QML type in a second QML file and
try to override the array there, when creating an instance of the child
class, the list contains the arrays concatenated instead of the overriding
array.
In the following example, I would expect the list to contain 2 elements
instead of 5. What are your thoughts? Should I fill a bug report and try to
provide a fix?

Best regards,

Unai Irigoyen

Example:
// containedtype.h //

#ifndef CONTAINEDTYPE_H

#define CONTAINEDTYPE_H

#include 

class ContainedType : public QObject

{

   Q_OBJECT

};

#endif // CONTAINEDTYPE_H

// mytype.h //

#ifndef MYTYPE_H

#define MYTYPE_H

#include 

#include 

#include "containedtype.h"


class MyType : public QObject

{

   Q_OBJECT

   Q_PROPERTY(QQmlListProperty myList READ myList)


   QQmlListProperty myList(){

  return QQmlListProperty(this, 0,

   _list_append,

   _list_count,

   _list_at,

   _list_clear);

   }


   private:

   QList m_myList;


   static inline void my_list_append(QQmlListProperty *
property,ContainedType * value)

   {

  MyType * instance = qobject_cast(property->object);

  if(instance)

  {

 instance->m_myList.append(value);

  }

   }

   static inline int my_list_count(QQmlListProperty * property)

   {

  MyType * instance = qobject_cast(property->object);

  if(instance)

  {

 return instance->m_myList.count();

  }

  else

  {

 return 0;

  }

   }

   static inline ContainedType *
my_list_at(QQmlListProperty * property, int index)

   {

  MyType * instance = qobject_cast(property->object);

  if(instance)

  {

 return instance->m_myList.at(index);

  }

  else

  {

 return nullptr;

  }

   }

   static inline void my_list_clear(QQmlListProperty * property)

   {

  MyType * instance = qobject_cast(property->object);

  if(instance)

  {

 instance->m_myList.clear();

  }

   }

};

#endif // MYTYPE_H

// main.cpp //

#include 

#include 

#include "mytype.h"


int main(int argc, char *argv[])

{

   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);


   QGuiApplication app(argc, argv);


   qmlRegisterType("array.override.test", 1, 0, "ContainedType");

   qmlRegisterType("array.override.test", 1, 0, "MyType");


   QQmlApplicationEngine engine;

   const QUrl url(QStringLiteral("qrc:/main.qml"));

   QObject::connect(, ::objectCreated,

, [url](QObject *obj, const QUrl ) {

   if (!obj && url == objUrl)

  QCoreApplication::exit(-1);

}, Qt::QueuedConnection);

   engine.load(url);


   return app.exec();

}


// BaseType.qml //

import array.override.test 1.0

MyType {

myList: [

ContainedType{},

ContainedType{},

ContainedType{}

]

}


// OverridenType.qml //

import array.override.test 1.0

BaseType {

myList: [

ContainedType{},

ContainedType{}

]

}

// main.qml //

import array.override.test 1.0

OverridenType {

}
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest