On 01/02/2016 20:46, Tomaz Canabrava wrote:
I can have a class DiveComputers that is a model based on QAbstractListModel, since any dive can have zero or more dive computers, I can have the method DiveComputers *diveComputers() on the class Dive as a Q_PROPERTY, and I can access it in QML via:

ListView {
    id: diveList
    model : diveListModel
    delegate {
        ListView {
            id: diveComputerList
            model: dive.diveComputers
        }
    }
}

Tomaz,
Your email above is extremely informative. I deal with two-way communication between the QML and C++. The above allows the QML to see a model on the C++ side. This takes care of getting data drom the C++ to the QML. I also use a signal emitted by the QML to update the model within C++, something as follows:

Class DownloadManager

Q_PROPERTY(QStringListModel *vendorModel READ getVendorModel WRITE setVendorModel NOTIFY vendorChanged)
   .......

signals:
    void vendorChanged();    // notification from C++ to QML

public slots:
void newVendorSlot(const QString &vendortext);// meant for incoming signal from QML. I need to connect this to the QML.


The middle two lines above allow communication of the vendorModel to the QML. The bottom line above allows the C++ to receive the signal from the QML. Normally, using QtQuickView I would have connected the QML signal to the C++ slot as follows:

    QObject *dcSelectPanel = view.rootObject();
QObject::connect(dcSelectPanel,SIGNAL(vendorChangedSignal(QString)),
&DownloadManager,SLOT(newVendorSlot(QString)));

But within the present context it looks like view.rootObject() is not easily accessible and I need an alternative way of connecting the QML signal to the C++ slot. Any suggestions? I have spent considerable time scanning for a discussion on this issue and cannot find any text. In QmlManager, many slots are created but I see no connect construct. I hope I am making sense?
Kind regards,
willem

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to