Why did such parameter(local class variable and promoted class variable using QT Designer) update synchronized?



  • Dear all,

    I make sample widget program using QT 5.8 and QT Designer GUI.
    I add QWidget and promoted class(It called glwidet_1 class).
    And also, I added local class variable glwidget_2 in mainwindow.

    I updated glwidget_2 parameter only, but glwidget_1 parameter updated at same time.

    glwidget_2->paramA and ui->widget->paramA are same.

    I would like to independent such parameter.

    How to independent that? and I would like to understand that synchronize timing.

    Best Regards,


  • Qt Champions 2016

    Hi
    In the context of a class. what you you mean by parameter ?

    Unless you made some of the class member variable static for glwidget_2 , there is no reason it should change for ui->widget->paramA

    The object in ui->xxx is another instance than any you put as a member in mainwindow.

    Or maybe I dont understand what you see.

    If its related to anything openGl then you should show code.



  • Hello mrjj,

    Thank you for your quick response.

    I write source code below.

    MainWindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QTimer>
    #include "glwidget.h"
    #include <QWheelEvent>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        GLWidget *controller;
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

    MainWindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        controller = new GLWidget();
    
        controller->val = 1.0;
    
    }
    

    glwidget.cpp

    #include "glwidget.h"
    
    GLWidget::GLWidget(QWidget *parent) :
        QGLWidget(parent)
    {
       
    }
    
    GLfloat val = 0.0;		//local variable
    
    void GLWidget::initializeGL() {
    
        qglClearColor(Qt::white); 
    
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    
        glEnable(GL_DEPTH_TEST);
    
    }
    
    void GLWidget::paintGL() {
    
    }
    
    void GLWidget::resizeGL(int w, int h){
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60.0, (GLdouble)w / (GLdouble)h, 1.0, 10.0);
    }
    
    

    glwidget.h

    #ifndef GLWIDGET_H
    #define GLWIDGET_H
    
    #include <QGLWidget>
    #include<iostream>
    #include <glu.h>
    #include <GLUT/glut.h>
    #include<math.h>
    
    class GLWidget : public QGLWidget
    {
        Q_OBJECT
    public:
        GLWidget(QWidget *parent = 0);
        ~GLWidget();
    
        void initializeGL();
        void paintGL();
        void resizeGL(int w, int h);
    
    };
    
    #endif // GLWIDGET_H
    

    I used source code above.

    And I tried

    cout << ui->widget->val; // A
    cout << controller->val; // B

    in MainWindow.cpp

    A and B is same value.
    (I expected val A is 0.0, val B is 1.0)

    Do you understand about this problem?

    Best regards,


  • Qt Champions 2016

    Hi
    I think understand.

    But it looks like
    GLfloat val = 0.0; //local variable
    is not inside the class ?
    Is that correct ?

    class GLWidget : public QGLWidget
    {
        Q_OBJECT
    public:
        GLWidget(QWidget *parent = 0);
        ~GLWidget();
    
        void initializeGL();
        void paintGL();
        void resizeGL(int w, int h);
        GLfloat val = 0.0;	 <<<<<<<< ?
    };
    


  • Thank you for your attention.
    I re-check source code and header file.
    It maybe solve the problem.
    #I have a mistake, sorry...

    Thanks a lot!


  • Qt Champions 2016

    @tomohiro01
    Ok. Super np.
    Happy work.


Log in to reply
 

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