Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Problem with simple Class
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
QPoint wsp; int stan; Tree(); Tree(int Tstan, int Twsp_x, int Twsp_y); Tree(const Tree & Ttree);
#endif // 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
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();
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@
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 :(
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 ?
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
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. ) ?
[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.