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. [SOLVED] shared variable causing problem
QtWS25 Last Chance

[SOLVED] shared variable causing problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 541 Views
  • 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 Offline
    H Offline
    habbas33
    wrote on last edited by
    #1

    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
    0
    • H Offline
      H Offline
      habbas33
      wrote on last edited by
      #2

      solved using member variable for int movie instead of global

      1 Reply Last reply
      0

      • Login

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