[Interest] C++ / QML headaches

Willem Ferguson willemferguson at zoology.up.ac.za
Fri Feb 12 07:29:05 CET 2016


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160212/3ef66901/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: C++QML1.jpg
Type: image/jpeg
Size: 92839 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160212/3ef66901/attachment.jpg>


More information about the Interest mailing list