[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
    {
    Q_OBJECT
    public:
    mainWindow();
    private slots:
    void planNewAtack();
    };
    #endif@



  • There could be too reasons for the above error

    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



  • MOC shouldn't have problems as long as you followed best practices and declared everything in separate headers with all files included in the project file.

    What exactly are you trying to achieve by inheriting Ui::MainWindow?



  • Method planNewAtack() is not implemented.



  • Ah yes, I recently stumbled upon this issue in Creator/GCC as well, this is NOT MSVC compiler specific at all. Even an empty temporary implementation did the trick



  • Thanks Volker.I forgot that I create the dialog in main constructor and forgot to delete that slot.



  • 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;
    public:
    dialogPlanAtacktest();
    };
    #endif@



  • It's impossible to say what's going wrong without seing the rest of the code.



  • i missed a letter in de header guard :)



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



  • I'm not used with Creator...I'll try the Creator when I will have a deeper undestanding in QT and more experience in it.I learnt C++ and Qt on my own and still got a lot to learn.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.