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

Update data send from class B to class A



  • Hello!, I want to send the values of the global var time from my class myopenglwidget.cpp to mainwindow.cpp, in a label called lb_ax, My var time changes values constantly, and I need to sending from myopenglwidget to mainwindow, those values in that label, here are some fragments of the most importantly part of my code:

    //mainwindow.cpp

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    MyOpenGLWidget *a = new MyOpenGLWidget;
    
    bool result = connect(a, SIGNAL(textChanged(QString)),ui->lb_ax, SLOT(setText(QString)));
    
    qDebug()<<"conn;" <<result;
    
    a->someFunctionThatChangesText("");
    
    QApplication::processEvents();
    QWidget::repaint();
    
    update();
    

    }

    //mainWindow.h

    public:
    void UpdateLabel(const QString text);

    //myopenglwidget.cpp

    void MyOpenGLWidget::someFunctionThatChangesText(const QString& newtext){
    emit textChanged(QString::number(time));
    }

    //myopenglwidget.h

    signals:
    void textChanged(QString);
    public:
    void someFunctionThatChangesText(const QString& newtext);

    I want to know what is the problem here, because now only send the initialized value of the var, that is 0, some ideas please??


  • Lifetime Qt Champion


Log in to reply