[SOLVED] shared variable causing problem
-
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]