Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with simple Class
QtWS25 Last Chance

Problem with simple Class

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.8k Views
  • 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 Offline
    L Offline
    LooQ
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LooQ
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • L Offline
            L Offline
            LooQ
            wrote on last edited by
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0
              • L Offline
                L Offline
                LooQ
                wrote on last edited by
                #7

                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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  0
                  • L Offline
                    L Offline
                    LooQ
                    wrote on last edited by
                    #9

                    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
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      [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
                      0

                      • Login

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