Question

I have code in C++ for saving and retrieving data from an XML file. I have some forms built in QML that I would like to hook up in such a way that when data is entered in my QML, processing is handled in C++, and searches are done for products via QML form, processed in C++ and list of product items are handed back to QML for display.

class ProcessRequests : public QObject
{
    Q_OBJECT
    Q_PROPERTY(string username READ username WRITE username)
    Q_PROPERTY(string useremail READ useremail WRITE useremail)
    Q_PROPERTY(string usercomplaint READ usercomplaint WRITE usercomplaint)


    public:

    ProcessRequests()
    {}
    ~ProcessRequests(){}

    Q_INVOKABLE void SubmitComplaint(){
     //TODO: Add Xml code to save the property values to file 

    }

};
Was it helpful?

Solution

I think your problem is to inter-communicate between QML and C++ code, you can do it with code like this:

//Product.cpp
QmlApplicationViewer viewer;

QDeclarativeEngine *engine = viewer.engine();
QDeclarativeContext *context = engine->rootContext();

context->setContextProperty("Product", this);

//Your QML File
Product.YourFunction(args);

OTHER TIPS

The topic is rather large, you'd better have a look at the docs, they're quite clear and there should be some tutorial as well. This is a good starting point: QML bindings in C++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top