Important: Please read the Qt Code of Conduct -

Problem with simple Class

  • 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


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


    #endif // TREE_H


    @#include "Tree.h"


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


    Tree::Tree(int Tstan, int Twsp_x, int Twsp_y)
    stan = Tstan;

    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;;
    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@

  • Moderators

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

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

  • Lifetime Qt Champion

    Do you compile tree.cpp ?

  • 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.@

  • Lifetime Qt Champion

    Can you show the content of your pro file ?

  • 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

    HEADERS += window.h

    FORMS += window.ui

  • Lifetime Qt Champion

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

  • 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. ) ?

  • Moderators

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

Log in to reply