Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why did such parameter(local class variable and promoted class variable using QT Designer) update synchronized?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.8k 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.
  • T Offline
    T Offline
    tomohiro01
    wrote on last edited by
    #1

    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,

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomohiro01
        wrote on last edited by
        #3

        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,

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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;	 <<<<<<<< ?
          };
          
          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomohiro01
            wrote on last edited by
            #5

            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!

            mrjjM 1 Reply Last reply
            1
            • T tomohiro01

              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!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @tomohiro01
              Ok. Super np.
              Happy work.

              1 Reply Last reply
              1

              • Login

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