I want to create a control panel for my application using Qt library and for this i create class
Controls
class
Controls
: create a slider and spin and a label and orgnize them in horizontal layout .
but when i want to create std::vector<Controls>
the program run without error but now controls is creating at all ! so why there is no controls.
Controls.h
class Controls
{
private:
QHBoxLayout Layout ;
string Controlname;
std::auto_ptr<QLabel> Label ;
std::auto_ptr<QSlider> Slider ;
std::auto_ptr<QSpinBox> Spin ;
public:
Controls();
Controls(QLayout &Parent , string name , const int &Default_value);
Controls(const Controls ©);
~Controls();
QLabel *const Get_Label()const { return Label.get() ; }
QSlider *const Get_Slider()const { return Slider.get() ; }
QSpinBox *const Get_Spin()const { return Spin.get() ; }
QHBoxLayout *const Get_Layout() {return &Layout;}
void SetValue(const int &newvalue);
Controls &operator= (const Controls ©);
};
Controls.cpp
Controls &Controls::operator= (const Controls ©)
{
Label = std::auto_ptr<QLabel> ( new QLabel() ) ;
Slider = std::auto_ptr<QSlider> ( new QSlider() ) ;
Spin = std::auto_ptr<QSpinBox> ( new QSpinBox() ) ;
this->Controlname = copy.Controlname ;
this->Slider.get()->setValue( copy.Slider.get()->value() );
this->Spin.get()->setValue( copy.Spin.get()->value() );
return *this ;
}
Controls::Controls(const Controls ©)
{
this->Controlname = copy.Controlname ;
this->Slider.get()->setValue( copy.Slider.get()->value() );
this->Spin.get()->setValue( copy.Spin.get()->value() );
}
Controls::Controls()
{
Label = std::auto_ptr<QLabel> ( new QLabel() ) ;
Slider = std::auto_ptr<QSlider> ( new QSlider() ) ;
Spin = std::auto_ptr<QSpinBox> ( new QSpinBox() ) ;
Slider->setValue(0);
Slider->setOrientation(Qt::Horizontal);
Label->setText(QString ("unamed"));
Spin->setValue(0);
Layout.addWidget(Label.get() , 0 , 0);
Layout.addWidget(Slider.get() , 0 , 0);
Layout.addWidget(Spin.get() , 0 , 0);
QObject::connect(Slider.get() , SIGNAL(valueChanged(int) ) , Spin.get() , SLOT(setValue(int)));
QObject::connect(Spin.get() , SIGNAL(valueChanged(int) ) , Slider.get() , SLOT(setValue(int)));
}
Controls::Controls(QLayout &Parent , string name , const int &Default_value)
{
Controlname = name ;
Label = std::auto_ptr<QLabel> ( new QLabel() ) ;
Slider = std::auto_ptr<QSlider> ( new QSlider() ) ;
Spin = std::auto_ptr<QSpinBox> ( new QSpinBox() ) ;
Slider->setValue(Default_value*100);
Slider->setOrientation(Qt::Horizontal);
Label->setText(QString (name.c_str()));
Spin->setValue(Default_value*100);
Layout.addWidget(Label.get() , 0 , 0);
Layout.addWidget(Slider.get() , 0 , 0);
Layout.addWidget(Spin.get() , 0 , 0);
QObject::connect(Slider.get() , SIGNAL(valueChanged(int) ) , Spin.get() , SLOT(setValue(int)));
QObject::connect(Spin.get() , SIGNAL(valueChanged(int) ) , Slider.get() , SLOT(setValue(int)));
Parent.addItem(&Layout);
}
void Controls::SetValue(const int &newvalue)
{
Slider.get()->setValue(newvalue);
}
Controls::~Controls()
{
}
main.cpp
int main(int argc, char *argv[])
{
QApplication app (argc , argv );
QVBoxLayout layout ;
auto_ptr<QWidget> Panel = auto_ptr<QWidget> (new QWidget()) ;
vector<Controls> g ;
g.push_back(Controls(layout , "WHITE_BALANCE_RED_V" , 56 ));
Panel.get()->setLayout(&layout);
Panel.get()->show();
return app.exec();
}
EDIT:
i remove auto_ptr destructor from ~controls , and when i run it again i get this exception
pure virtual method called
terminate called without an active exception
- i initialized sliders and spin in copy constructor