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. [PROBLEM]::can't find a way to cooperate with .cpp file
Forum Updated to NodeBB v4.3 + New Features

[PROBLEM]::can't find a way to cooperate with .cpp file

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    johnnykyp
    wrote on last edited by
    #1

    I want to be able to change the text, of text edits in my qml file, from my .cpp file; and the values of variables in my .cpp file, from the mouse areas in my qml file... Yet i can't seem to be able to find a way to do this.

    main.cpp:
    @
    #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
    int p1pts;
    int p2pts;
    int p1unaddedpts;
    int p2unaddedpts;
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    QmlApplicationViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
    viewer.setMainQmlFile&#40;QLatin1String("qml/counter/main.qml"&#41;&#41;;
    viewer.showExpanded();
    
    return app->exec(&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johnnykyp
      wrote on last edited by
      #2

      main.qml:
      @
      import QtQuick 1.1

      Rectangle {
      width: 360
      height: 640
      color: "#000000"
      border.color: "#000000"
      property int p1pts: 20;
      property int p2pts: 20;
      MouseArea {
      id: mousearea1
      x: 0
      y: 0
      width: 360
      height: 640
      clip: true
      smooth: true
      hoverEnabled: false
      anchors.rightMargin: 0
      anchors.bottomMargin: 0
      anchors.topMargin: 0
      anchors.leftMargin: 0
      anchors.fill: parent
      onClicked: {
      }

          Rectangle {
              id: add1
              x: 48
              y: 180
              width: 25
              height: 25
              color: "#33ff33"
              radius: 4
      
              MouseArea {
                  id: mouse_area1
                  anchors.fill: parent
      
              }
          }
      
          Rectangle {
              id: subtract1
              x: 103
              y: 180
              width: 25
              height: 25
              color: "#ff3333"
              radius: 4
      
              MouseArea {
                  id: mouse_area2
                  anchors.fill: parent
              }
          }
      
          Rectangle {
              id: add2
              x: 236
              y: 180
              width: 25
              height: 25
              color: "#33ff33"
              radius: 4
      
              MouseArea {
                  id: mouse_area3
                  anchors.fill: parent
              }
          }
      
          Rectangle {
              id: subtract2
              x: 291
              y: 180
              width: 25
              height: 25
              color: "#ff3333"
              radius: 4
      
              MouseArea {
                  id: mouse_area4
                  anchors.fill: parent
              }
          }
      
          Rectangle {
              id: rectangle1
              x: 48
              y: 30
              width: 80
              height: 40
              color: "#3333ff"
      
              TextEdit {
                  id: text_edit1
                  x: 0
                  y: 0
                  width: 80
                  height: 40
                  color: "#ffffff"
                  text: "20"
                  horizontalAlignment: TextEdit.AlignHCenter
                  font.pixelSize: 30
              }
          }
      
          Rectangle {
              id: rectangle2
              x: 236
              y: 30
              width: 80
              height: 40
              color: "#3333ff"
      
              TextEdit {
                  id: text_edit2
                  x: 0
                  y: 0
                  width: 80
                  height: 40
                  color: "#ffffff"
                  text: "20"
                  horizontalAlignment: TextEdit.AlignHCenter
                  font.pixelSize: 30
              }
          }
      
          Rectangle {
              id: rectangle3
              x: 48
              y: 111
              width: 80
              height: 30
              color: "#00ffef"
      
              TextEdit {
                  id: text_edit3
                  x: 0
                  y: 0
                  width: 80
                  height: 30
                  color: "#ffffff"
                  text: "0"
                  horizontalAlignment: TextEdit.AlignHCenter
                  font.pixelSize: 25
              }
          }
      

      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        johnnykyp
        wrote on last edited by
        #3

        the remaining .qml file:
        @

            Rectangle {
                id: rectangle4
                x: 236
                y: 111
                width: 80
                height: 30
                color: "#00ffef"
        
                TextEdit {
                    id: text_edit4
                    x: 0
                    y: 0
                    width: 80
                    height: 30
                    color: "#ffffff"
                    text: "0"
                    horizontalAlignment: TextEdit.AlignHCenter
                    font.pixelSize: 25
                }
            }
        
            Rectangle {
                id: rectangle5
                x: 48
                y: 234
                width: 25
                height: 25
                color: "#ffffff"
        
                Text {
                    id: text1
                    text: qsTr("+")
                    font.bold: true
                    horizontalAlignment: Text.AlignHCenter
                    anchors.fill: parent
                    font.pixelSize: 20
                }
        
                MouseArea {
                    id: mouse_area5
                    anchors.fill: parent
                }
            }
        
            Rectangle {
                id: rectangle6
                x: 103
                y: 234
                width: 25
                height: 25
                color: "#ffffff"
        
                Text {
                    id: text2
                    text: qsTr("-")
                    horizontalAlignment: Text.AlignHCenter
                    anchors.fill: parent
                    font.bold: true
                    font.pixelSize: 20
                }
        
                MouseArea {
                    id: mouse_area6
                    anchors.fill: parent
                }
            }
        
            Rectangle {
                id: rectangle7
                x: 236
                y: 234
                width: 25
                height: 25
                color: "#ffffff"
        
                Text {
                    id: text3
                    text: qsTr("+")
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    font.bold: true
                    font.pixelSize: 20
                }
        
                MouseArea {
                    id: mouse_area7
                    anchors.fill: parent
                }
            }
        
            Rectangle {
                id: rectangle8
                x: 291
                y: 234
                width: 25
                height: 25
                color: "#ffffff"
        
                Text {
                    id: text4
                    text: qsTr("-")
                    anchors.fill: parent
                    font.bold: true
                    horizontalAlignment: Text.AlignHCenter
                    font.pixelSize: 20
                }
        
                MouseArea {
                    id: mouse_area8
                    anchors.fill: parent
                }
            }
        
            Rectangle {
                id: rectangle9
                color: "#8f0000"
                anchors.top: parent.top
                anchors.topMargin: 555
                anchors.right: parent.right
                anchors.rightMargin: 100
                anchors.left: parent.left
                anchors.leftMargin: 100
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 40
        
                Text {
                    id: text5
                    color: "#0000ff"
                    text: qsTr("EXIT")
                    font.bold: true
                    horizontalAlignment: Text.AlignHCenter
                    anchors.fill: parent
                    font.pixelSize: 34
                }
        
                MouseArea {
                    id: mouse_area9
                    anchors.fill: parent
                    onClicked: { Qt.quit(); }
                }
            }
        
        
        }
        

        }
        @

        1 Reply Last reply
        0
        • J Offline
          J Offline
          johnnykyp
          wrote on last edited by
          #4

          Someone please help me... I can't find the solution anywhere...

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gennon
            wrote on last edited by
            #5

            You should read this:

            http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-topic.html

            C++ into QML:
            http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-contextproperties.html

            QML in C++:
            http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-interactqmlfromcpp.html

            /Gen

            1 Reply Last reply
            0
            • J Offline
              J Offline
              johnnykyp
              wrote on last edited by
              #6

              thank you SO MUCH!!!

              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