2

I'm kind of new to QT programming, and I encountered this strange error when I was trying to have the program open a new dialog that I have created with a press of a button.

I am trying to open table.ui, robotdance.ui, and graph.ui from scouting.ui by pressing a button. In scouting.cpp:

table *teamtable = new table(this); teamtable->show();

I have included the header files for the .ui's into the scouting.cpp, but it's giving me this error:

scouting.obj:-1:

error: LNK2019: unresolved external symbol "public: __thiscall graph::graph(class QWidget *)" (??0graph@@QAE@PAVQWidget@@@Z) referenced in function "private: void __thiscall Scouting::on_actionGraphs_triggered(void)" (?on_actionGraphs_triggered@Scouting@@AAEXXZ)

Two more errors are shown which are similar to this one.

Why is this happening? I followed this guy's tutorial and did what he did but he doesn't seem to get any errors.

scouting.cpp:

http://pastebin.com/NEEu9jmM

table.h:

http://pastebin.com/BMDCkcwJ

table.cpp

is in the additional comment section, since I can't post more than 2 links.

Community
  • 1
  • 1
Lawlhwut
  • 27
  • 1
  • 6
  • Without any details about the error all I can say is read this: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – drescherjm Jan 22 '13 at 03:24
  • Also how are you linking to Qt libraries? Just adding the includes or include folders to a visual studio project will not work. – drescherjm Jan 22 '13 at 03:26
  • Im using qt creator. And the error is: scouting.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall graph::graph(class QWidget *)" (??0graph@@QAE@PAVQWidget@@@Z) referenced in function "private: void __thiscall Scouting::on_actionGraphs_triggered(void)" (?on_actionGraphs_triggered@Scouting@@AAEXXZ) pretty much the same thing for the other 2, and there is 1 more error saying "Lnk1120: 3 unresolved externals" – Lawlhwut Jan 22 '13 at 03:32
  • Make sure you add both your own table.h and table.cpp to the project and implement table::table(QWidget* parent) in the .cpp. – Frank Osterfeld Jan 22 '13 at 07:47
  • They are all part of the project. And what do you mean implement it in the .cpp? – Lawlhwut Jan 22 '13 at 08:06
  • Who is "this guy"? I suppose you forgot a link ;-) – Tim Meyer Jan 22 '13 at 09:12
  • this guy: https://www.youtube.com/watch?v=wUH_gu2HdQE&list=SP2D1942A4688E9D63&index=5 – Lawlhwut Jan 24 '13 at 01:26
  • table.cpp http://pastebin.com/ZuNSHfkd – Lawlhwut Jan 24 '13 at 01:27

3 Answers3

3

I believe you are building your application on windows. I suspect that visual studio project files are not updated with the added files, and that is causing the problem. Just delete the visual studio build folder, and rebuild. It will work fine.

Mohan
  • 31
  • 2
2

Usually there are two possible reasons for this:


A) You did not add graph.cpp (and other .cpp files) to your .pro file


B) Your header file looks somewhat like this

class graph : public QWidget
{
public:
    graph( QWidget* parent );
    ~graph();

    ...
}

but your source file (.cpp) does not contain this:

#include "graph.h"

graph::graph( QWidget* parent ) :
    QWidget( parent )
{
    ...
}

graph::~graph()
{
    ...
}
Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
  • 1
    Hm not sure then.. "Unresolved external symbol X" usually means the linker does not find the implementation of X. I guess your only chance is to work through all the answers in the post drescherjm linked in a comment to your question. – Tim Meyer Jan 23 '13 at 09:54
1

This is an error from linker that can not link all of the object files together.

  • your header and source files added to your project?
  • if you are using any library in Qt, you might add them to your project's .pro file (for example: QT += core gui webkitwidgets network)
  • add all of library directives of classes that you are using in your codes. (such as #include <QDialog>)
  • Don't forget to delete all of compiler generated output directory from your project's path, take attention DO NOT remove your project's source directory, after delete project's output directory first right click on your project and click Run qmake then build your project.
Reza Ebrahimi
  • 3,623
  • 2
  • 27
  • 41
  • I created the project in Qtcreator, so bullet 2 seems unnecessary. For bullet 1, yes I added all the header files necessary. And yes for bullet 3 as well. – Lawlhwut Jan 24 '13 at 00:39
  • 1
    for bullet 2 it's necessary too, if you want to test this, add a QWebView and it's header file to your project, then configure it then run, you will be get that failed, because of the webkitwidgets not added to your namespaces in .pro file (in Qt 5.0), be aware that Qt Creator does not add automatically these stuff to your .pro file, you could check manually them and if needs add it to your file, – Reza Ebrahimi Jan 24 '13 at 12:28
  • 1
    how do I add them manually? Because it seems the files are all within my project because when I look at the actual directory of where the project is located, it contains everything necessary. – Lawlhwut Jan 24 '13 at 17:05
  • 1
    please post your table.cpp and graph.cpp and scouting.h for further review – Reza Ebrahimi Jan 24 '13 at 17:19
  • table.cpp is in the original question's additional comments section. graph.cpp and scouting.h http://pastebin.com/e88u567K – Lawlhwut Jan 24 '13 at 19:33
  • Ah yes! That worked! Although Im getting other problems. Thank you! – Lawlhwut Jan 26 '13 at 08:05