Partage
  • Partager sur Facebook
  • Partager sur Twitter

Erreur a la compilation

    17 juin 2008 à 10:55:02

    voici mon tout petit projet. Il a un fenêtre principale de type QMainWindow et si on clique dans le menu sur Nouvelle inscription . Une autre fenêtre devrait s 'ouvrir pour prendre les coordonnées du nouvel inscrit.

    erreur

    In file included from FenPrincipale.h:3,
                     from FenPrincipale.cpp:1:
    FenIns.h:3:16: QGui: No such file or directory
    In file included from FenPrincipale.h:3,
                     from FenPrincipale.cpp:1:
    FenIns.h:5: error: expected class-name before '{' token
    FenIns.h:6: error: ISO C++ forbids declaration of `QLineEdit' with no type
    FenIns.h:6: error: expected `;' before '*' token
    FenIns.h:7: error: ISO C++ forbids declaration of `QLineEdit' with no type
    FenIns.h:7: error: expected `;' before '*' token
    FenIns.h:8: error: ISO C++ forbids declaration of `QLineEdit' with no type
    FenIns.h:8: error: expected `;' before '*' token
    FenIns.h:10: error: expected `)' before '*' token
    FenPrincipale.cpp: In constructor `FenPrincipale::FenPrincipale()':
    FenPrincipale.cpp:26: warning: unused variable 'menuEdition'
    FenPrincipale.cpp:27: warning: unused variable 'menuAffichage'
    FenPrincipale.cpp: In member function `void FenPrincipale::NouvInsc()':
    FenPrincipale.cpp:35: error: no matching function for call to `FenIns::FenIns(Fe
    nPrincipale* const)'
    FenIns.h:5: note: candidates are: FenIns::FenIns()
    FenIns.h:5: note:                 FenIns::FenIns(const FenIns&)
    FenPrincipale.cpp:36: error: 'class FenIns' has no member named 'exec'
    mingw32-make[1]: *** [release/FenPrincipale.o] Error 1
    mingw32-make[1]: Leaving directory `C:/Documents and Settings/maxime/Mes documen
    ts/C++/patro'
    mingw32-make: *** [release] Error 2
    
    C:\Documents and Settings\maxime\Mes documents\C++\patro>


    FenPricipale.h
    #ifndef HEADER_FENPRINCIPALE
    #define HEADER_FENPRINCIPALE
    #include "FenIns.h"
    
    #include <QtGui>
    
    class FenPrincipale : public QMainWindow
    {
          Q_OBJECT
    	public:
    		FenPrincipale();
    	public slots:
               void NouvInsc(void);
    
    	private: QMenu *menuFichier;
    	               QAction *actionQuitter;
    	               QAction *actionNouvIns;
    	               QAction *actionAfficheMembre;
    	               QAction *actionCalendrier;
                 QMenu *menuEdition;
                 QMenu *menuAffichage;
                 QWidget *zoneCentrale ;
                 
    };
    
    
    #endif
    


    FenPrincipale.cpp
    #include "FenPrincipale.h"
    #include "FenIns.h"
    
    
    FenPrincipale::FenPrincipale()
    {
                                  // Les  Menus
       QMenu *menuFichier = menuBar()->addMenu("&Fichier");
           
           QAction *actionNouvIns= new QAction("Nouvelle &inscription",this);
           menuFichier->addAction(actionNouvIns);
           QObject::connect(actionNouvIns, SIGNAL(triggererd()), this, SLOT(NouvInsc()));
           
           QAction *actionAfficheMembre= new QAction("Liste des &membres", this);
           menuFichier->addAction(actionAfficheMembre);
           
           QAction *actionCalendrier= new QAction("&Calendrier",this);
           menuFichier->addAction(actionCalendrier);
           
           QAction *actionQuitter = new QAction("&Quitter", this);
           menuFichier->addAction(actionQuitter);
           actionQuitter->setShortcut(QKeySequence("Ctrl+Q"));
           connect(actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
           
             
       QMenu *menuEdition = menuBar()->addMenu("&Edition");
       QMenu *menuAffichage = menuBar()->addMenu("&Affichage");
           
       QWidget *zoneCentrale = new QWidget;
       setCentralWidget(zoneCentrale);
    
    }
     void FenPrincipale::NouvInsc(void)
     {
          FenIns *nouvelleInscription = new FenIns(this);
          nouvelleInscription->exec();
     }
    

    FeIns.cpp
    FenIns::FenIns(QWidget *parent) :QDialog(parent)
    {
         QLineEdit *nom= new QLineEdit();
         QLineEdit *prenom= new QLineEdit();
         QLineEdit *age= QLineEdit();
         QFormLayout *formLayout = new QFormLayout();
         formLayout->addRow("Nom", nom);
         formLayout->addRow("Prenom", prenom);
         
         QVBoxLayout *layoutPrincipal = new QVBoxLayout;
         layoutPrincipal->addLayout(formLayout);
        this.setLayout(layoutPrincipal);
    }
    


    FenIns.h
    #ifndef DEF_FENINS
    #define DEF_FENINS
    #include <QGui>
    class FenIns : public QDialog
    {
          private: QLineEdit *nom;
                   QLineEdit *prenom;
                   QLineEdit *age;
                   
          public: FenIns(QMainWindow *parent);
    };
    #endif
    



    Je ne comprends vraiment pas :(
    • Partager sur Facebook
    • Partager sur Twitter
      17 juin 2008 à 10:58:52

      #include <QtGui> et pas QGui à la ligne 3 du dernier fichier.
      • Partager sur Facebook
      • Partager sur Twitter
      Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
        17 juin 2008 à 11:04:46

        merci ca va mieux.
        Mais j'ai encore un petit probleme...
        void FenPrincipale::NouvInsc(void)
         {
              FenIns *nouvelleInscription = new FenIns(zoneCentrale);
              nouvelleInscription->exec();
         }
        


        Il ne veut pas que j'envoie une reference sur zoneCentrale.... Alors que j'en ai bien besoin dans FenIns....
        • Partager sur Facebook
        • Partager sur Twitter
        Anonyme
          17 juin 2008 à 11:20:24

          La variable zoneCentrale est déclarée dans le constructeur donc détruite à la fin de l'appel de ce dernier...

          Il faut que tu déclare une variable QWidget *zoneCentrale dans ta classe FenPrincipale ou plus simplement utiliser ce code :

          FenIns *nouvelleInscription = new FenIns(this->centralWidget()); //! La méthode QMainWindows::centralWidget() retourne un ponteur sur le Widget occupant la zone centrale
          nouvelleInscription->exec();
          
          • Partager sur Facebook
          • Partager sur Twitter
            17 juin 2008 à 11:23:10

            hélas non, ca ne fonctionne pas...

            release/FenPrincipale.o(.text+0xe13):FenPrincipale.cpp: undefined reference to `
            FenIns::FenIns(QWidget*)'
            • Partager sur Facebook
            • Partager sur Twitter
            Anonyme
              17 juin 2008 à 11:27:10

              Truc tout bête mais la déclaration et l'implémentation du constructeur ne correspondent pas... L'un demande un QMainWindow * et l'autre un QWidget *

              Sinon, si c'est simplement pour l'utiliser en tant que parent, tu fais :

              FenIns *nouvelleInscription = new FenIns(this);
              nouvelleInscription->exec();
              
              • Partager sur Facebook
              • Partager sur Twitter
                17 juin 2008 à 11:38:58

                oui ca c'est tout con ... Je commence tout doucement a m'y faire a ce langage mais c'est pas encore gagné....

                sinon, est ce que je peut faire ceci dans FenIns.cpp:
                this.setLayout(layoutPrincipal);
                

                il me le refuse.
                FenIns.cpp: In constructor `FenIns::FenIns(QMainWindow*)':
                FenIns.cpp:3: error: type `class QMainWindow' is not a direct base of `FenIns'
                FenIns.cpp:7: error: cannot convert `QLineEdit' to `QLineEdit*' in initializati
                n
                FenIns.cpp:14: error: `setLayout' is not a type
                FenIns.cpp:14: error: request for member of non-aggregate type before '(' token
                • Partager sur Facebook
                • Partager sur Twitter
                Anonyme
                  17 juin 2008 à 11:54:06

                  Pour l'erreur ligne 7, tu déclares un pointeur sur un QLineEdit, il doit être initialisé avec new QLineEdit(/* On peut rajouter this ici */).

                  Pour la ligne 14 : this retourne un pointeur sur l'objet, donc on utilisera -> à la place du point.

                  Sinon, pour la ligne 3, compare bien la déclaration de ton constructeur et son implémentation, j'ai l'impresssion qu'il y a encore une différence entre les deux
                  • Partager sur Facebook
                  • Partager sur Twitter
                    17 juin 2008 à 12:13:40

                    Pour la ligne 3, je pense que tu as mis QMainWindow(parent) a la place de QDialog(parent) dans ton constructeur.
                    • Partager sur Facebook
                    • Partager sur Twitter

                    Erreur a la compilation

                    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                    • Editeur
                    • Markdown