Valeur d'attribut inatteignable (utilise Qt)
Coucou,
j'ai un petit soucis d'obtention d'un attribut d'une classe depuis une autre.
mon code se compose des fichiers suivants :
main.cpp
MainFrame.cpp
MainFrame.h
EditorFrame.h
EditorFrame.cpp
le code du main où je crée mon objet window de classe MainFrame.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <QApplication>
#include <QtGui>
#include "MainFrame.h"
#include "EditorFrame.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainFrame window;
window.show();
return app.exec();
} |
Mon MainFrame.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include "MainFrame.h"
using namespace std;
MainFrame::MainFrame()
{
setFixedSize(400,600);
//GroupBox Definition de la classe
QGroupBox *definitionClasse = new QGroupBox("Définition de la classe");// déclaration du groupebox classe
definitionClasse->setMaximumHeight(90);
QFormLayout *defClasse = new QFormLayout; // Ajout d'un formulaire contenant 2 lignes de texte appartenant au Groupbox defclasse
QLineEdit *nameLineEdit = new QLineEdit; // Définition des lignes de texts
QLineEdit *classeLineEdit = new QLineEdit;
defClasse->addRow("Nom : ", nameLineEdit); // Ajout des lignes dans le formulaire
defClasse->addRow("Classe parente : ", classeLineEdit);
definitionClasse->setLayout(defClasse); // Intégration du formulaire dans le groupbox
// GroupeBox Option
QGroupBox *option = new QGroupBox("Optio&ns");
QCheckBox *cBox_protegeHeader = new QCheckBox("Pro&teger le header contre les boucles infinies",option); // Creation des 3 boutons checkable
QCheckBox *cBox_constructDefaut = new QCheckBox("Gene&rer un constructeur par défaut",option);
QCheckBox *cBox_genererDestruct = new QCheckBox("Generer &le destructeur",option);
QVBoxLayout *VBoxOption = new QVBoxLayout(option); // Creation d'un VBox pour les 3 bouttons
VBoxOption->addWidget(cBox_protegeHeader);
VBoxOption->addWidget(cBox_constructDefaut);
VBoxOption->addWidget(cBox_genererDestruct);
option->setLayout(VBoxOption); // Ajout du VBox dans le groupebox
//GroupeBox Commentaires
QGroupBox *addComment = new QGroupBox("&Ajouter des commentaires");
addComment->isCheckable();
addComment->setCheckable(1); // Ajoute la croix
QFormLayout *commentaireFormLayout = new QFormLayout; // Ajout d'un formlayout
QLineEdit *auteurLineEdit = new QLineEdit; // définition des éléments du formulaire
QDateEdit *dateCreaDateEdit = new QDateEdit(QDate::currentDate());
QTextEdit *descriptionTextEdit = new QTextEdit;
commentaireFormLayout->addRow(tr("A&uteur : "),auteurLineEdit); // Ajout des lignes dans le formulaire
commentaireFormLayout->addRow(tr("Date de &création : "),dateCreaDateEdit);
commentaireFormLayout->addRow(tr("De&scription : "), descriptionTextEdit);
addComment->setLayout(commentaireFormLayout); // Ajout du formulaire dans le groupbox
// PushButton
QPushButton *pButton_generer = new QPushButton("Générer"); // Ajout de 2 boutons poussoirs
QPushButton *pButton_quitter = new QPushButton("Quitter");
// QHBox pour les PushButton
QHBoxLayout *HBox_boutton = new QHBoxLayout; // Définition d'un HBox et ajout des 2 bouttons
HBox_boutton->addWidget(pButton_generer);
HBox_boutton->addWidget(pButton_quitter);
HBox_boutton->setAlignment(Qt::AlignRight);
//Vertical box
QVBoxLayout *layoutPrincipal = new QVBoxLayout(this);
layoutPrincipal->addWidget(definitionClasse); // Ajout du layout de groupebox
layoutPrincipal->addWidget(option); // Ajout du layout de groupebox
layoutPrincipal->addWidget(addComment); // Ajout du layout de groupebox
layoutPrincipal->addLayout(HBox_boutton);
this->setLayout(layoutPrincipal); // Ajout du VBox dans la fenetre principale
/***** DEFINITION DES SIGNAUX *****/
QString test= "Coucou" ;
connect(pButton_quitter,SIGNAL(clicked()),this,SLOT(close()));
connect(pButton_generer,SIGNAL(clicked()),this,SLOT(open_gen()));
/***** Recupération des variables *****/
QString nom = nameLineEdit->text();
QString classeParente = classeLineEdit->text();
QString nomauteur = auteurLineEdit->text();
QString description = descriptionTextEdit->toPlainText();
}
MainFrame::~MainFrame()
{
// delete m_label;
}
void MainFrame::open_gen()
{
//QMessageBox::information(this,"Bonjour",this->nomauteur);
EditorFrame windowsGen;
windowsGen.exec();
}
QString MainFrame::getDescription()
{
return nomauteur;
} |
MainFrame.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#ifndef HEADER_H_MAINFRAME
#define HEADER_H_MAINFRAME
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QFormLayout>
#include <QLineEdit>
#include <QString>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QDateEdit>
#include <QTextEdit>
#include <QPushButton>
#include "EditorFrame.h"
class MainFrame : public QWidget
{
Q_OBJECT
public:
MainFrame();
~MainFrame();
QString getDescription();
public slots:
void open_gen();
private:
QDateEdit *dateCreaDateEdit;
QCheckBox *cBox_protegeHeader;
QCheckBox *cBox_constructDefaut;
QCheckBox *cBox_genererDestruct;
QFormLayout *commentaireFormLayout;
QFormLayout *defClasse;
QGroupBox *definitionClasse;
QGroupBox *addComment;
QGroupBox *option;
QLineEdit *nameLineEdit;
QLineEdit *classeLineEdit;
QLineEdit *auteurLineEdit;
QVBoxLayout *fenetrePrincipale;
QVBoxLayout *layoutPrincipal;
QVBoxLayout *VBoxOption;
QHBoxLayout *HBox_boutton;
QPushButton *pButton_generer;
QPushButton *pButton_quitter;
QTextEdit *descriptionTextEdit;
QString nom;
QString classeParente;
QString nomauteur;
QString description;
};
#endif |
EditorFrame.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include "EditorFrame.h"
#include "MainFrame.h"
using namespace std;
EditorFrame::EditorFrame(QString description)
{
QVBoxLayout *contenant = new QVBoxLayout;
QTextEdit *textedit = new QTextEdit(this);
QPushButton *m_quitter = new QPushButton;
contenant->addWidget(textedit);
contenant->addWidget(m_quitter);
this->show();
}
EditorFrame::EditorFrame()
{
description = window.getDescription(); // ERREUR EditorFrame.cpp(22) : error C2228: left of '.getDescription' must have class/struct/union
QVBoxLayout *contenant = new QVBoxLayout;
QTextEdit *textedit = new QTextEdit(this);
QPushButton *m_quitter = new QPushButton;
contenant->addWidget(textedit);
contenant->addWidget(m_quitter);
textedit->setText(description);
this->show();
}
EditorFrame::~EditorFrame()
{
} |
EditorFrame.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#ifndef HEADER_H_EDITORFRAME
#define HEADER_H_EDITORFRAME
#include <QApplication>
#include <QWidget>
#include <QMessageBox>
#include <QString>
#include <QPushButton>
#include "MainFrame.h"
#include <QDialog>
class EditorFrame : public QDialog
{
public:
EditorFrame(QString description);
EditorFrame();
~EditorFrame();
private:
QString description;
};
#endif |
Et j'obtiens cette erreur sous VC++2k8:
Code:
1 2
|
1>.\EditorFrame.cpp(22) : error C2228: left of '.getDescription' must have class/struct/union |
Et sous mingw32 en console Qt :
Code:
1 2
|
EditorFrame.cpp:22: error: insufficient contextual information to determine type |
Voila, j'ai beau retourner la question dans tous les sens , je comprend po :(