Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How I can connect circularGauge qml with signal in cpp



  • my code in QML:

    import QtQuick 2.6
    import QtQuick.Controls 2.1
    import QtQuick.Extras 1.4
    import QtQuick.Controls.Styles 1.4
    
    Rectangle{
    
        width:300
        height: 300
        //property alias CircularGauge:circularGauge
        function setvalue(value){ circularGauge.value = value; }
    
    
    
      CircularGauge{
    
          id: circularGauge
          anchors.centerIn: parent
                 minimumValue : -30
                 maximumValue : 30
                 style: CircularGaugeStyle
                 {
                     minimumValueAngle : -90
                     maximumValueAngle  : 90
    
                     needle:Item
                     {
         //                Rectangle
         //                {
         //                    width: outerRadius * 0.02
         //                    height: outerRadius * 0.7
         //                    color: "Light Blue"
         //                }
                     }
                     foreground: Item
                     {
         //                Rectangle {
         //                    width: outerRadius * 0.2
         //                    height: width
         //                    radius: width / 2
         //                    color: "#e5e5e5"
         //                    anchors.centerIn: parent
         //                }
                     }
    
                     tickmarkLabel:Text
                     {
                         color:"Black"
                         text : styleData.value
                     }
                 }
             }
    
    
    
    
    
      }
    
    
    
    
    
    //MY CODE IN mainWindow cpp:
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtQml>
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        ui->qml->setSource(QUrl("qrc:///uil.qml"));
        ui->qml->show();
       
        auto rootObject = ui->qml->rootObject();
        connect(this,SIGNAL(setGauge(QVariant)),rootObject,SLOT(setvalue(QVariant)));
    
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_dial_sliderMoved(int position)
    {
        emit setGauge(15.5);
    }
    
    
    
    
    

    15.5 is an example of a number..Can you help me?



  • @vale88 I solved


Log in to reply