PDA

View Full Version : create a class



nymar
27th February 2013, 10:30
hi
i want to create my own class and use it in another project. I'm following a Tutorial but i'm blocked now. Look what the tuto did
First he made a project FenPrincipale
header

#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
#include <QMainWindow>
class FenPrincipale : public QMainWindow
{
public:
FenPrincipale();
private:
};
#endif // FENPRINCIPALE_H
main

#include <QApplication>
#include <QtGui>
#include <QMainWindow>
#include “FenPrincipale.h”
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}
.cpp

#include “FenPrincipale.h”
FenPrincipale::FenPrincipale()
{
}
it works fine for me, but later in the tuto he make a second project
with the following main

#include <QApplication>
#include <QtGui>
#include “FenPrincipale.h”
FenPrincipale::FenPrincipale()
{
QVBoxLayout *layout = new QVBoxLayout;
QDirModel *modele = new QDirModel;
QTreeView *vue = new QTreeView;
vue->setModel(modele);
layout->addWidget(vue);
setLayout(layout);
}
i don't know what he did exactly he wasn't clear he just dropped that code but what i did is
i made new project and paste FenPrincipale.h in the same folder with the new project but this is what i got
C:\Qt\Qt5.0.1\5.0.1\mingw47_32\lib\libqtmaind.a(qt main_win.o):-1: In function `WinMain@16’:
Q:\qt5_workdir\w\s\qtbase\src\winmain\qtmain_win.c pp:131: erreur : undefined reference to `qMain(int, char**)’
collect2.exe:-1: erreur : error: ld returned 1 exit status

wysota
27th February 2013, 10:40
You need a main() function in your project.

nymar
27th February 2013, 11:20
how should it be written the main ? like that ?


#include <QApplication>
#include <QtGui>
#include <QMainWindow>
#include "FenPrincipale.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return app.exec();
}

wysota
27th February 2013, 11:34
Maybe you should ask the person who wrote the tutorial? :)

ChrisW67
27th February 2013, 23:35
main.cpp is probably not listed in your PRO file SOURCES variable.