Results 1 to 5 of 5

Thread: create a class

  1. #1
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default create a class

    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
    Qt Code:
    1. #ifndef FENPRINCIPALE_H
    2. #define FENPRINCIPALE_H
    3. #include <QtGui>
    4. #include <QMainWindow>
    5. class FenPrincipale : public QMainWindow
    6. {
    7. public:
    8. FenPrincipale();
    9. private:
    10. };
    11. #endif // FENPRINCIPALE_H
    To copy to clipboard, switch view to plain text mode 
    main
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include <QMainWindow>
    4. #include “FenPrincipale.h”
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. FenPrincipale fenetre;
    9. fenetre.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. #include “FenPrincipale.h”
    2. FenPrincipale::FenPrincipale()
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 
    it works fine for me, but later in the tuto he make a second project
    with the following main
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include “FenPrincipale.h”
    4. FenPrincipale::FenPrincipale()
    5. {
    6. QVBoxLayout *layout = new QVBoxLayout;
    7. QDirModel *modele = new QDirModel;
    8. QTreeView *vue = new QTreeView;
    9. vue->setModel(modele);
    10. layout->addWidget(vue);
    11. setLayout(layout);
    12. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by wysota; 27th February 2013 at 10:41. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: create a class

    You need a main() function in your project.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: create a class

    how should it be written the main ? like that ?

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include <QMainWindow>
    4. #include "FenPrincipale.h"
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. FenPrincipale fenetre;
    9. fenetre.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 27th February 2013 at 11:35. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: create a class

    Maybe you should ask the person who wrote the tutorial?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: create a class

    main.cpp is probably not listed in your PRO file SOURCES variable.

Similar Threads

  1. Replies: 7
    Last Post: 1st March 2011, 23:02
  2. qt creator create class problem
    By foxhengxing in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2010, 16:32
  3. Create Own Signal send to different class
    By arpspatel in forum Qt Programming
    Replies: 0
    Last Post: 5th April 2010, 23:46
  4. class and event create
    By electronicboy in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2009, 23:07
  5. Replies: 0
    Last Post: 9th March 2009, 03:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.