Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Problem with simple Class

    General and Desktop
    3
    10
    3497
    Loading More Posts
    • 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.
    • L
      LooQ last edited by

      Hi,
      I'm newbie in Qt, I'm created my own very simple class. And when I want to create some object of my class something goes wrong. I don't know what's going on. Probably I missed something in code. Let take a look on my code. Thanks!

      My class: tree.h

      @#ifndef TREE_H
      #define TREE_H

      #include <QPoint>

      class Tree
      {

      public:

      QPoint wsp;
      int stan;
      
      Tree();
      Tree(int Tstan, int Twsp_x, int Twsp_y);
      Tree(const Tree & Ttree);
      

      };

      #endif // TREE_H
      @

      TREE.CPP

      @#include "Tree.h"

      Tree::Tree()
      {
      }

      Tree::Tree(const Tree &Ttree)
      {
      stan = Ttree.stan;
      wsp = Ttree.wsp;

      }

      Tree::Tree(int Tstan, int Twsp_x, int Twsp_y)
      {
      stan = Tstan;
      wsp.setX(Twsp_x);
      wsp.setY(Twsp_y);
      }
      @

      And the last one main.cpp
      @#include <QApplication>
      #include <QVector>
      #include "drzewo.h"
      #include "window.h"

      int main(int argc, char *argv[])
      {
      // QVector <Tree> Forest;
      Tree One(20,20,0); // <- Here is the problem

      QApplication a(argc, argv);
      window w;
      w.show();
      
      return a.exec&#40;&#41;;
      

      }
      @

      This is very simple and works perfect in clear C++ in VS2012 but in QT something goes wrong.

      My error looks like this:
      @main.obj:-1: error:LNK2019: unresolved external symbol "public: __cdecl Tree::Tree(int,int,int)" (??0Tree@@QEAA@HHH@Z) referenced in function main

      debug\Fire.exe:-1: error:LNK1120: 1 unresolved externals@

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Wrong include... in main.cpp you are including "drzewo.h" but your header is called "Tree.h".

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • L
          LooQ last edited by

          There is "Tree.h" for now, but error is the same :(

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Do you compile tree.cpp ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • L
              LooQ last edited by

              When I was trying to do this I received this error :

              @22:41:09: Running steps for project Fire...
              22:41:09: Configuration unchanged, skipping qmake step.
              22:41:09: Starting: "D:\Qt\Qt5.0.2\Tools\QtCreator\bin\jom.exe" -f Makefile.Debug debug/Tree.obj
              Error: Target debug/Tree.obj doesn't exist.
              22:41:09: The process "D:\Qt\Qt5.0.2\Tools\QtCreator\bin\jom.exe" exited with code 2.
              Error while building/deploying project Fire (kit: Desktop Qt 5.0.2 MSVC2012 64bit)
              When executing step 'Make'
              22:41:09: Elapsed time: 00:00.@

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Can you show the content of your pro file ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • L
                  LooQ last edited by

                  Of course,

                  @#-------------------------------------------------

                  Project created by QtCreator 2013-06-08T16:27:11

                  #-------------------------------------------------

                  QT += core gui

                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                  TARGET = Fire
                  TEMPLATE = app

                  SOURCES += main.cpp
                  window.cpp
                  Tree.cpp

                  HEADERS += window.h
                  Tree.h

                  FORMS += window.ui
                  @

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    Did you also try the usual: delete the shadow build and rebuild the project ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 0
                    • L
                      LooQ last edited by

                      Yes, I did. This is not helping me. I have a question : When I want to create my own Class (CTRL+N) > C++ Class. Do I have to set up Base Class (QObject etc. ) ?

                      1 Reply Last reply Reply Quote 0
                      • sierdzio
                        sierdzio Moderators last edited by

                        [quote author="LooQ" date="1370728174"]When I want to create my own Class (CTRL+N) > C++ Class. Do I have to set up Base Class (QObject etc. ) ?[/quote]

                        No, you don't need to. This choice of parent class is just a convenient helper, to be used when needed.

                        (Z(:^

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post