lundi 31 juillet 2017

Error while subclassing QGridLayout

I'm trying to subclassing QGridLayout for building a widget to set as layout for a QDialog. When I try to do "setLayout(view);" inside the View_currentSpec constructor I have an error from the compiler which says that "view is not declared for this scope". Am I doing something wrong?

class View_currentSpec : public QDialog{
Q_OBJECT
public:
    View_currentSpec(species* spec, std::string sho, QWidget* parent = 0);
private:
    species* currentSpec;
    std::string showType;
};

View_currentSpec :: View_currentSpec(species* spec, std::string sho, 
                                     QWidget* parent)
  : QDialog(parent), currentSpec(spec), showType(sho){

     setWindowTitle("Visualizzazione specie");
     setFixedWidth(500);
     setFixedHeight(500);

     if(View_Species* view = Spec_Selection :: build(currentSpec)){
         if(showType == "show") view -> buildShow();
     }
     setLayout(view);
}

View_Species* Spec_Selection :: build(species* currentSpec){
    if(dynamic_cast<animals*>(currentSpec))
        return new View_Species(currentSpec);
    return nullptr;
}

class View_Species : public QGridLayout{
    Q_OBJECT
public:
    View_Species(species* spec, QWidget* parent = nullptr);

    void buildShow();
protected:
    species* currentSpec;

    QLineEdit* nome_spec;

    virtual void buildSpecView();
};

View_Species :: View_Species(species* spec, QWidget* parent)
    : QGridLayout(parent), currentSpec(spec){
}

void View_Species :: buildShow(){
    buildSpecView();
}

void View_Species :: buildSpecView(){

    QLabel* nome = new QLabel("Nome Specie");

    nome_spec = new QLineEdit();
    nome_spec -> setText("aaa");

    addWidget(nome, 0, 0);
    addWidget(nome_spec, 1, 0);

}

Aucun commentaire:

Enregistrer un commentaire