[Interest] C++ / QML headaches

Dmitry Volosnykh dmitry.volosnykh at gmail.com
Fri Feb 12 07:54:00 CET 2016


Willem,
try removing Q_INVOKABLE before VendorModel() method. Withouth this
moc-related "keyword" VendorModel() method will remain "visible" to moc
since it is declared as a READ-accessor inside corresponding Q_PROPERTY
macro.

On Fri, Feb 12, 2016 at 9:29 AM Willem Ferguson <
willemferguson at zoology.up.ac.za> wrote:

> I include an image explaining much of the context of the problem I
> encounter.
>
> I have a QML combobox that needs to respond to a C++ QStringListModel. I
> do this as follows:
>
> At the start where the QML machine is initialised (at the top of the
> attached image)
> 1) Define and instantiate the underlying C++ class (DownloadManager) as a
> global object (downloadhelper),
>     visible to the C++ code far away.
> 2) Define a context pointer to downloadhelper. The handle for this pointer
> is "downloadhelper".
>
> Within the downloadmanager class (the C++ code):
> 1) Define a property set (Q_PROPERTY) that allows QML to see several
> structures inside the C++ code.
> 2) Define the model vendorModel to be used by the QML combobox. The
> vendorModel is accessible both
>     as a QStringListModel (vendorModel) and as a function that returns a
> pointer to a QStrinListModel
>     (VendorModel()).
>
> In the QML:
> 1) The downloadhelper object is seen with the QML code, visible by the
> italic font of "downloadhelper" as well
>     some of the visible parts within downloadhelper, offered in the
> dropdown list (right-hand side of attached image)
>     In fact, the function downloadhelper.fill_computer_list() works as
> expected and fills venderModel (the QStringListModel)
>     with an appropriate QStringList.
>
> The result: If, within the model specification in the QML:
> 1) If I choose "vendorModel" from the dropdown list and execute, there is
> a segfault at the model definition in the QML
>      Commenting out the model definition eliminates the segfault.
> 2) If I choose "VendorModel()", the QML processor does not recognise the
> identifier
> 3) If I choose the source QStringList (not the model based in that
> stringlist) I get an error message:
>     ERROR: Unknown method return type: QStringListModel*
> 4) If I choose VendorModel (as defined in the Q_PROPERTY), then I get the
> output in the black box at the bottom of the image.
>     If I take the Q_PROPERTY definition as a yard stick, the READ handle
> VendorModel should be the appropriate one.
>     But VendorModel is not even listed in the dropdown list in the QML
> code in the image.
>
> Any comments or suggestion will be very valuable.
> Kind regards,
> willem
>
> _______________________________________________
> 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/20160212/f6b81fd4/attachment.html>


More information about the Interest mailing list