[SOLVED]Microsoft Visual Studio 2010 compiler
After i introduce the Q_OBJECT macro in a class I get the folowing error:
- mainwindow.obj : error LNK2019: unresolved external symbol "public: __thiscall dialogPlanNewAtack::dialogPlanNewAtack(void)" (??0dialogPlanNewAtack@@QAE@XZ) referenced in function "public: __thiscall mainWindow::mainWindow(void)" (??0mainWindow@@QAE@XZ)
- 1>moc_mainwindow.obj : error LNK2019: unresolved external symbol "private: void __thiscall mainWindow::planNewAtack(void)" (?planNewAtack@mainWindow@@AAEXXZ) referenced in function "private: static void __cdecl mainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@mainWindow@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z)
- 1>debug\\mainWindow.exe : fatal error LNK1120: 2 unresolved externals
I tried fixing this by running qmake on the files but it didn’t worked.I have no other ideea on how to fix this.Please help me.
This is how the declaration of the class looks:
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include "ui_mainWindow.h"
- #include <QMainWindow>
- class mainWindow: public QMainWindow,Ui::MainWindow
- private slots:
- void planNewAtack();
1. moc is not executed for the mainwindow class to generate c++ code for the compiler.
2.If moc is executed which qmake do by default then implementation of mainwindow and the declaration of mainwindow will be in the same file
make sure you are not doing the above two things…
the declaration is in mainwindow.h and the implementantion is in mainwindow.cpp and moc_mainwindow.cpp .
- if !defined(Q_MOC_OUTPUT_REVISION)
- #error "The header file 'mainwindow.h' doesn't include <QObject>."
- #elif Q_MOC_OUTPUT_REVISION != 63
- #error "This file was generated using the moc from 4.8.0. It"
- #error "cannot be used with the include files from this version of Qt."
- #error "(The moc has changed too much.)"
This is the file generated by moc
Now i have another error,hope you read this.Why I receive the error ‘class’ type redefinition?I changed the class name and I still receive this error.The header of the class is something like this:
- #ifndef DIALOGPLANNEWATACK_H
- #define DIALOGPLANNEWATAC_H
- #include <QDialog>
- #include "ui_dialogPlanNewAtack.h"
- class dialogPlanAtacktest :public QDialog,Ui::dialogPlanNewAtack
- int i;
Why don’t you just let Creator do the header guards for you? Instead of creating a header and cpp file just create a new class and you got it all.
You can also use Creator to automatically create method implementations and even sync changes in them. Besides saving time this is a great way to avoid nasty little typos.
You can still use the MSVC compiler from Creator, it will be detected and you will be offered MSVC build configurations.