Importing canvas data to a C++ backend



  • I'm designing something in QML that needs to draw something based on people's inputs to draw something on a canvas. The inputs have to go through an equation in order to get the info for what needs to be drawn on the screen. This equation also needs x and y coordinates in order to come up with values. Is there any way where I am able to send each individual x and y coordinate data to a C++ backend in order to enter it into an equation?

    Thanks!



  • @GoldRatio hi,
    if you want to call c++ method with parameters from your QML, yes u can.

    class BackEnd : public QObject
    {
        Q_OBJECT
    Q_INVOKABLE void fnc(float x,float y){
    //..
    }
    
    public:
        explicit BackEnd(QObject *parent = nullptr);
    ...
    };
    

    in your main.cpp include, and create an instance of BackEnd.
    Put that instance as ContextProperty to be able to call its methods (Q_INVOKABLES and public slots ) from QML

    BackEnd be;
    engine.rootContext()->setContextProperty("back",&be);
    
    

    use from qml

    Component.onCompleted: { back.fnc(10,11) }
    

    http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html



  • @LeLev Sorry I may have been a little vague. My problem is not that I am unable to connect import a function to the Backend, but that I don't know how to import the data from each individual point on a canvas into the backend.

    Example - Say if I create a QML canvas and I need to do something different with each coordinate, depending on the x and y values of its coordinates are (ie. sending the values into an equation to be evaluated). I don't know how to pull out these values and send them into the backend as variables to each be evaluated, and then have that information sent back to the canvas and interacted based on these values.

    Sorry for all of the trouble, I'm pretty new this stuff.

    Thanks Again!



  • Not sure again this is what you need but all properties qml side have onPropertieChanged signal
    peroperty real x
    onXChanged : {back.fnc(x,y)}



  • a QML canvas and I need to do something different with each coordinate

    What does the coordinate of a canvas mean?

    How is the canvas painted ?
    If it's from user input, send the user input to your function first and the drawing part should then be driven by your backend, with a model, signals, whatever.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.