Le MOC ne veut pas compiler "correctement" mes sources
Bonjour, j'essaye de définir mes classes et de les implémenter uniquement dans les fichiers d'en-tête (.hpp). Ce qui est parfaitement possible en C++, voici mes sources :
main.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
|
/*
*GGFM = Générateur Graphique de Fonctions Mathématiques
*License = BY-NC-SA (http://creativecommons.org/licenses/by-nc-sa/2.0/fr/)
*Créateur = Abdelite
*GGFM/main.cpp
*/
#include <QtCore>
#include <QtGui>
#include <QtGlobal>
#include "FenetrePrincipale.hpp"
#include "Afficheur.hpp"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenetrePrincipale fenetrePrincipaleDeGGFM;
return app.exec();
} |
FenetrePrincipale.hpp :
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
|
/*
*GGFM = Générateur Graphique de Fonctions Mathématiques
*License = BY-NC-SA (http://creativecommons.org/licenses/by-nc-sa/2.0/fr/)
*Créateur = Abdelite
*GGFM/FenetrePrincipale.hpp
*/
#ifndef HEADER__FenetrePrincipale
#define HEADER__FenetrePrincipale
#include <QtCore>
#include <QtGui>
#include <QtGlobal>
#include "Afficheur.hpp"
class FenetrePrincipale : public QWidget
{
Q_OBJECT
public:
FenetrePrincipale(QWidget* widgetParent = 0);
protected:
QGraphicsView* m;
Afficheur* i;
void resizeEvent(QResizeEvent* event);
};
FenetrePrincipale::FenetrePrincipale(QWidget* widgetParent)
{
this->setWindowTitle("Repére Orthogonal");
this->setWindowIconText("icone.png");
this->resize(400, 450);
i = new Afficheur(this);
m = new QGraphicsView(i, this);
m->move((((this->width()) / 2) - ((m->width()) / 2)), (((this->height()) / 2) - ((m->height()) / 2)));
m->show();
this->show();
}
void FenetrePrincipale::resizeEvent(QResizeEvent* event)
{
m->move((((this->width()) / 2) - ((m->width()) / 2)), (((this->height()) / 2) - ((m->height()) / 2)));
}
#endif //HEADER__FenetrePrincipale |
Afficheur.hpp :
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
|
/*!
*GGFM = Générateur Graphique de Fonctions Mathématiques
*License = BY-NC-SA (http://creativecommons.org/licenses/by-nc-sa/2.0/fr/)
*Créateur = Abdelite
*GGFM/Afficheur.hpp
*/
#ifndef HEADER__Afficheur
#define HEADER__Afficheur
#include <QtCore>
#include <QtGui>
#include <QtGlobal>
class Afficheur : public QGraphicsScene
{
Q_OBJECT
public:
Afficheur(QObject* objectParent = 0);
QPointF returnPointOfRepereStandart(QPointF pointOfRepereOrthogonal);
QPointF returnPointOfRepereOrthogonal(QPointF pointOfRepereStandart);
protected:
QPointF pointOriginRepereOrthogonal;
QPointF pointOriginRepereStandart;
};
Afficheur::Afficheur(QObject* objectParent)
{
this->setSceneRect(0, 0, 100, 100);
pointOriginRepereStandart = QPointF(0, 0);
pointOriginRepereOrthogonal = QPointF(50, 50);
QPoint kiko(0, 0);
QPointF kiku(0, 4.5678);
QLineF lino(this->returnPointOfRepereStandart(kiko), this->returnPointOfRepereStandart(kiko));
QLineF linu(this->returnPointOfRepereStandart(kiku), this->returnPointOfRepereStandart(kiku));
this->addLine(lino);
this->addLine(linu);
}
QPointF Afficheur::returnPointOfRepereStandart(QPointF pointOfRepereOrthogonal)
{
return QPointF((pointOriginRepereOrthogonal.x() + pointOfRepereOrthogonal.x()), (pointOriginRepereOrthogonal.y() - pointOfRepereOrthogonal.y()));
}
QPointF Afficheur::returnPointOfRepereOrthogonal(QPointF pointOfRepereStandart)
{
return QPointF((pointOfRepereStandart.x() - pointOriginRepereOrthogonal.x()), (pointOriginRepereOrthogonal.y() - pointOfRepereStandart.y()));
}
#endif //HEADER__Afficheur |
Voilà, maintenant quand j'essaye de compiler, on me retourne un tas d'erreur :
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
|
release/moc_Afficheur.o:moc_Afficheur.cpp:(.text+0x0): multiple definition of `Afficheur::returnPointOfRepereStandart(QPointF)'
release/main.o:main.cpp:(.text+0x0): first defined here
release/moc_Afficheur.o:moc_Afficheur.cpp:(.text+0x38): multiple definition of `Afficheur::returnPointOfRepereOrthogonal(QPointF)'
release/main.o:main.cpp:(.text+0x38): first defined here
release/moc_Afficheur.o:moc_Afficheur.cpp:(.text+0xf0): multiple definition of `Afficheur::Afficheur(QObject*)'
release/main.o:main.cpp:(.text+0xec): first defined here
release/moc_Afficheur.o:moc_Afficheur.cpp:(.text+0x2f0): multiple definition of`Afficheur::Afficheur(QObject*)'
release/main.o:main.cpp:(.text+0x2ec): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x0): multiple definition of `Afficheur::returnPointOfRepereStandart(QPointF)'
release/main.o:main.cpp:(.text+0x0): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x38): multiple definition of `Afficheur::returnPointOfRepereOrthogonal(QPointF)'
release/main.o:main.cpp:(.text+0x38): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0xf0): multiple definition of `FenetrePrincipale::resizeEvent(QResizeEvent*)'
release/main.o:main.cpp:(.text+0x70): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x16c): multiple definition of `Afficheur::Afficheur(QObject*)'
release/main.o:main.cpp:(.text+0xec): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x36c): multiple definition of `Afficheur::Afficheur(QObject*)'
release/main.o:main.cpp:(.text+0x2ec): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x56c): multiple definition of `FenetrePrincipale::FenetrePrincipale(QWidget*)'
release/main.o:main.cpp:(.text+0x4ec): first defined here
release/moc_FenetrePrincipale.o:moc_FenetrePrincipale.cpp:(.text+0x784): multiple definition of `FenetrePrincipale::FenetrePrincipale(QWidget*)'
release/main.o:main.cpp:(.text+0x7a4): first defined here
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\GGFM.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Users/tyuityuityui/Desktop/GGFM'
mingw32-make: *** [release] Error 2 |
Si j'implémente les méthodes dans le corps de la classe, ou si j'utilise les .cpp, ou encore si je retire la macro Q_OBJECT, tout semble fonctionner. Le problème dois sûrement venir du moc.
Pourriez-vous s'il vous plaît m'aider à ce que ce mini-projet compile, merci d'avance.