Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED] shared variable causing problem

    General and Desktop
    1
    2
    458
    Loading More Posts
    • 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.
    • H
      habbas33 last edited by

      Hi i am new to object oriented programming and dont know how to get rid of this problem. here I intent to make three animation plots

      @
      subwindow_movie *child_Movie = new subwindow_movie;

      child_Movie->setGeometry(20,100,620,560);
      
      child_Movie->setplot(0);
      
      child_Movie->show();
      
      subwindow_movie *child_Movie1 = new subwindow_movie;
      child_Movie1->setGeometry(680,100,620,560);
      child_Movie1->setplot(1);
      child_Movie1->show();
      
      
      subwindow_movie *child_Movie2 = new subwindow_movie;
      
      child_Movie2->setGeometry(325,350,620,560);
      
      child_Movie2->setplot(2);
      
      child_Movie2->show();
      

      @

      but the problem is that they all share same value of setplot i,e when the third subwindow_movie is created child_movie0 and child_movie1 both setplot values become 2; how to get rid of that... below is the set value funxtion inside the class

      @
      #include "subwindow_movie.h"

      #include "ui_subwindow_movie.h"

      #include "plot.h"

      #include <qapplication.h>

      #include <qmainwindow.h>

      int movie;

      subwindow_movie::subwindow_movie(QWidget *parent) :

      QDialog(parent),
      
      ui(new Ui::subwindow_movie)
      

      {

      ui->setupUi(this);
      

      }

      subwindow_movie::~subwindow_movie()
      {
      delete ui;
      }

      void subwindow_movie::setplot(int value)

      {
      if (value ==0)

       {   d_plot0 = new Plot( this );
      
           movie=0;}
      
       else if (value ==1)
      
       {   d_plot1 = new Plot( this );
      
           movie=1;}
      
       else if (value ==2)
      
       {   d_plot2 = new Plot( this );
      
           movie=2;}
      

      }

      void subwindow_movie::on_movie_slider_valueChanged(int value)

      {
      if (movie ==0)

      {  d_plot0->setAlpha(value);
      
         }
      else if (movie ==1)
      
      {  d_plot1->setAlpha(value);
      
      }
      else if (movie ==2)
      
      {  d_plot2->setAlpha(value);
      
      }
      

      }
      @

      the real problem is "int movie " which changes for with new child_movie

      [edit: added missing coding tags @ SGaist]

      1 Reply Last reply Reply Quote 0
      • H
        habbas33 last edited by

        solved using member variable for int movie instead of global

        1 Reply Last reply Reply Quote 0
        • First post
          Last post