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
{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 problemQApplication a(argc, argv); window w; w.show(); return a.exec();
}
@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 maindebug\Fire.exe:-1: error:LNK1120: 1 unresolved externals@
-
Wrong include... in main.cpp you are including "drzewo.h" but your header is called "Tree.h".
-
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.@ -
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 = appSOURCES += main.cpp
window.cpp
Tree.cppHEADERS += window.h
Tree.hFORMS += window.ui
@ -
Did you also try the usual: delete the shadow build and rebuild the project ?
-
[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.