[Interest] Function overload and QML
Arthur Buldauskas
whinemore at gmail.com
Sat Feb 28 19:39:19 CET 2015
Hey, not sure if you solved your problem by now, but here is one solution.
I've notice you are trying to pass a string. If you change the const
QVariant& to a const QString& parameter it will call the proper overloaded
function for you.
On Mon, Feb 16, 2015 at 7:17 AM, Federico Buti <bacarozzo at gmail.com> wrote:
> Ok...sorry for the spam. I've just noticed this sentence in the
> documentation QVariantList and QVariantMap to JavaScript Array and Object
> <http://doc.qt.io/qt-5/qtqml-cppintegration-data.html>:
>
> [...] Similarly, if a C++ type uses a QVariantList
> <http://doc.qt.io/qt-5/qvariant.html#QVariantList-typedef> or QVariantMap
> <http://doc.qt.io/qt-5/qvariant.html#QVariantMap-typedef> type for a
> property type or method parameter, the value can be created as a JavaScript
> array or object in QML, and is automatically converted to aQVariantList
> <http://doc.qt.io/qt-5/qvariant.html#QVariantList-typedef> or QVariantMap
> <http://doc.qt.io/qt-5/qvariant.html#QVariantMap-typedef> when it is
> passed to C++.
>
> So, following that "or object in QML", is this the case I've encountered?
> The string object was trasformed in a QVariantList, matching the first
> signature in the reorderd header?
> Thanks again,
> F.
>
> ---
> Federico Buti
>
> On 16 February 2015 at 13:09, Federico Buti <bacarozzo at gmail.com> wrote:
>
>> Hi list.
>>
>> I've made an intensive use of INVOKABLE/SLOT functions in QML and I've
>> never encounted any problem. Up until now.
>>
>> I'm sure that function overloading works properly since I've used it a
>> lot (also the related commit can be found here
>> <https://qt.gitorious.org/qt/tmartsums-qt/commit/1d7b672fd46abab51a0124ad19aad18e5d14f1a8>).
>> However, I've noticed a strange behaviour by working with the
>> ArrayDataModel available here <https://github.com/dridk/ArrayDataModel>.
>>
>> I've registered an instance of the model as a context property in the
>> usual way:
>>
>> ArrayDataModel model;
>>
>> engine.rootContext()->setContextProperty("model", &model);
>>
>>
>> Then in QML I've inserted a call to a SLOT in this way:
>>
>> Button {
>>
>> text: "click me!"
>>
>> onClicked: {
>>
>> model.insert(model.size(), "Item " + (model.size() + 1));
>>
>> }
>>
>> }
>>
>>
>> Theoretically, the method to be invoked by the runtime should be
>>
>> void insert (int i, const QVariant &value);
>>
>>
>> However, if I exchange position of overloaded functions, i.e. if I write
>> the header as
>> ββ
>>
>> Q_SLOT void insert (int i, const QVariant &value);
>>
>> Q_SLOT void insert (int i, const QVariantList &values);
>>
>>
>> instead of the original
>>
>> Q_SLOT void insert (int i, const QVariantList &values);
>>
>> Q_SLOT void insert (int i, const QVariant &value);
>>
>>
>> the function which is called is (wrongly)
>>
>>
>>
>> Q_SLOT void insert (int i, const QVariantList &values);
>>
>>
>> βIs this
>> β a BUG, an intended behaviour, a specific conversion JS <--> C++, e.g.
>> the parameter is seen as a single-item-array and made match with the wrong
>> overload? Or something else I cannot understand? :)
>> Thanks in advance for any insight,
>> F.
>>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150228/95ff6389/attachment.html>
More information about the Interest
mailing list