PDA

View Full Version : how to infrom a different class of a change in variable..


salmanmanekia
14th August 2008, 20:54
hi..
this problem is more related to c++ then qt but it also requires previous info about qt so i cannot consult to any pure c++ forums and c++ forum on qtcentre seems to be quite inactive so i thought of banging my question here.. :)
anyways the problem is here..atlast ;)
in the below class scenario i inform the 'superClass' with the value of 'record_click' from 'child1',the superClass then informs 'child2's record_click of this new value...but as you can see that i am using update() function in child2 in which i do record_click-- and i wanted this change to be made to superClass and child1's record_click...i mean that record_click of these two classes should also reduce themself by one
pls see the class 'child1' first ...then the 'super' class


//in superClass

connect(myChild1,SIGNAL(recordClicked(int)),this,S LOT(requestRecord(int)));

void superClass::requestRecord(int rec_clicks)
{
record_clicks = rec_clicks;
//emit requestedRecord(); //this is useless in this case because i wanted to also emit a signal to other widget to listen to
}

void superClass::recognitionAccept() //this method is succesfully called from another class and now i want to pass the recordclick value to the child..
{
..
myChild2->showAcceptedProgress(record_clicks);
..
}

// in my child1 class
..
connect(recordButton,SIGNAL(clicked()),this,SLOT(r eactToRecord()));
..
void child1::reactToRecord()
{
record_clicks++;
disableRecordButton();
emit recordClicked(record_clicks);
}
//in child2 class

void child2::showAcceptedProgress(int rec_clicks)
{
record_clicks = rec_clicks;
..
update();
}

jacek
14th August 2008, 21:25
and i wanted this change to be made to superClass and child1's record_click...i mean that record_click of these two classes should also reduce themself by one
Does this mean that both super class and child class have their own record_click member variables?

salmanmanekia
15th August 2008, 01:32
Does this mean that both super class and child class have their own record_click member variables?

ya,i think it should because i have to reduce it as i said by one which mean i have to access it,one idea can be declaring it as public maybe ,but i think i just dont want to exposs unneccesary code to other classes...:),
i have also tried some derefrencing but this also doesnt seem to work...

jacek
15th August 2008, 16:36
ya,i think it should because i have to reduce it as i said by one which mean i have to access it,one idea can be declaring it as public maybe ,but i think i just dont want to exposs unneccesary code to other classes...:),
i have also tried some derefrencing but this also doesnt seem to work...
I don't quite follow you.

Anyway if you need to use some member variable in subclasses, either make it protected or give your subclasses some protected interface.