Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Create class
Forum Updated to NodeBB v4.3 + New Features

Create class

Scheduled Pinned Locked Moved Qt Creator and other tools
10 Posts 3 Posters 16.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nymar
    wrote on 27 Feb 2013, 09:15 last edited by
    #1

    Hi

    i'm a begginer and i want to learn how to create my own class and use it in another project later.
    i did like this and it didn't work i create new project in which i made my new class for exemple "mywindow" ,i compile it and it works. now i open another project and i call it #include<mywindow> i got an error "#include<mywindow> no such file or directory "

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BelenMuñoz
      wrote on 27 Feb 2013, 09:27 last edited by
      #2

      The old class has to be in the same folder, if it's not there, you'll have to add the path in the .pro file.
      I hope it helps.

      Me casé con un enano pa jartarme de reí.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on 27 Feb 2013, 09:34 last edited by
        #3

        Hi all what i can advice to you for now is start learn C++ language and Qt.
        For C++ language:
        "http://www.cplusplus.com/doc/tutorial/":http://www.cplusplus.com/doc/tutorial/
        or many other free resources(use google)
        for Qt:
        C++ GUI Programming with Qt 4 – By Jasmin Blanchette, Mark Summerfield
        "doc":http://qt-project.org/doc/[qt-project.org]
        best one and free videos: "http://voidrealms.com/tutorials.aspx?filter=qt":http://voidrealms.com/tutorials.aspx?filter=qt

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nymar
          wrote on 27 Feb 2013, 09:37 last edited by
          #4

          just tell me about the syntax of the path for ex
          i have folder in desktop called my project in which i have 2 project one is my class "mywindow" the second is the new project
          so if i follow u i should write the path in .pro file but how

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nymar
            wrote on 27 Feb 2013, 09:49 last edited by
            #5

            qxoz i'm following a tuto of c++ and Qt
            look what he 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 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(qtmain_win.o):-1: In function `WinMain@16':

            Q:\qt5_workdir\w\s\qtbase\src\winmain\qtmain_win.cpp:131: erreur : undefined reference to `qMain(int, char**)'

            collect2.exe:-1: erreur : error: ld returned 1 exit status
            @

            Edit: please spend a little effort to make your post readable. Using @ tags around code sections already helps a lot, but properly indented code would be even better; Andre

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on 27 Feb 2013, 10:22 last edited by
              #6

              Can you give a link to that tutorial or post your project on some file hosting? So i can understand what you doing wrong and help.
              and please edit your previos post use @ tag for code.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nymar
                wrote on 27 Feb 2013, 11:17 last edited by
                #7

                it's long 600 pages u need to follow it from begin i don't think it's a good idea but u can help me by explaining step by step how to create a class and call it in another project i would appreciate it

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qxoz
                  wrote on 27 Feb 2013, 12:12 last edited by
                  #8

                  Sure. Lets see your code. You say
                  [quote author="nymar" date="1361958556"]
                  it works fine for me, but later in the tuto he make a second project
                  with the following main [/quote]

                  Try change your class as:
                  .h
                  @#ifndef FENPRINCIPALE_H
                  #define FENPRINCIPALE_H
                  #include <QtGui>
                  #include <QMainWindow>

                  class FenPrincipale : public QMainWindow
                  {
                  Q_OBJECT
                  public:
                  explicit FenPrincipale(QWidget *parent = 0);
                  FenPrincipale();
                  private:
                  QVBoxLayout *layout;
                  QDirModel *modele;
                  QTreeView *vue;
                  };

                  #endif // FENPRINCIPALE_H@
                  .cpp
                  @FenPrincipale::FenPrincipale(QWidget *parent) :
                  QMainWindow(parent)
                  {
                  layout = new QVBoxLayout;
                  modele = new QDirModel;
                  vue = new QTreeView;
                  vue->setModel(modele);
                  layout->addWidget(vue);
                  setLayout(layout);
                  }@

                  leave main() as in first project
                  @#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();
                  }@

                  Try this and tell me what you got.

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nymar
                    wrote on 27 Feb 2013, 13:54 last edited by
                    #9

                    i'm slow i know it but i have 2 projects now
                    1-FenPrincipale contains (FenPrincipale.h +main.cpp+ FenPrincipale.cpp)

                    2-test contains (main.cpp + FenPrincipale.h (which i imported from the first project))
                    and if i'm not wrong ur making a new project in which u define a new class and u use it inside the same project isn't it ?

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      qxoz
                      wrote on 27 Feb 2013, 16:16 last edited by
                      #10

                      Well you can also use existing class in many projects. It's doesn't matter you create or include new class.

                      1 Reply Last reply
                      0

                      10/10

                      27 Feb 2013, 16:16

                      • Login

                      • Login or register to search.
                      10 out of 10
                      • First post
                        10/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved