Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Importing canvas data to a C++ backend

Importing canvas data to a C++ backend

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 647 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GoldRatio
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GoldRatio
        wrote on last edited by
        #3

        @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!

        1 Reply Last reply
        0
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved