PDA

View Full Version : Declaration not working



kenny_isles
1st March 2007, 05:57
Hi All,

I have a problem in QT Designer. And i do not have the right words to address my problem. So please apologize if i tell anything wrong.


void ColorPref::High_Range()
{

this->Obj_Dec();
hr->setPaletteBackgroundColor(color_hr);
ok->setEnabled(TRUE);

}


void ColorPref::Obj_Dec()
{
QColor color_hr = QColorDialog::getColor(
QColor(),
this, "color dialog" );
}

These are two functions. Obj_Dec() is a function that declares the QColor object.
And I am calling it from the function High_Range();

It gives the following error

.ui/../ColorPref.ui.h: In member function `virtual void ColorPref::High_Range()':
.ui/../ColorPref.ui.h:27: error: `color_hr' undeclared (first use this function).ui/../ColorPref.ui.h:27: error: (Each undeclared identifier is reported only on


Can anyone plz tell me as to why this is happening and hence solve the error.

Note :- Obj_Dec() is Public

Thanks and Regards
Kenny

wysota
1st March 2007, 10:13
It doesn't have anything to do with Designer or Qt at all - it is a C++ issue. "color_hr" is a local variable - it is valid only in scope of the function it was declared in. Once the function returns, the object gets destroyed (and will be created again when you enter the function the next time). If you want to have a variable which you can reference from different methods, either make it a global variable or a member of the class (latter preferred).