Question

I have received a Visual C++ QT based project from our customer. I have installed QT libraries then I have compiled the project. The Project was compiled without any problems.

Now, I need to include a new additional GUI interface with the existing project. I have created a GUI in QT designer then saved in the source directory of VC++ project. Then I have written .h and .cpp file for new GUI and could call this interface. Now I need to include SIGNALS and SLOTS, when I include Q_OBJECT in .h file. I have compilation error.

These are the errors, please help me to solve this problem:

unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BetaLineServer::metaObject(void)const " (?metaObject)

unresolved external symbol "public: virtual void * __thiscall BetaLineServer::qt_metacast(char const *)"

unresolved external symbol "public: virtual int __thiscall BetaLineServer::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@
Was it helpful?

Solution

You probably just need to add your .ui, .cpp and .h files to the project file.

Qt will run 'moc' on the ui file if it's listed there, which creates source code to supply your missing symbols.

OTHER TIPS

Any time you add a Q_OBJECT macro to a class you need to be sure to rerun qmake and then compile.

All you need is to compile the header files with moc that contain Q_OBJECT macro. And how to do that? here it is

  1. You can manually type commands for compiling moc or uic files OR

  2. -> Install Qt-VS addin. http://qt.nokia.com/downloads/visual-studio-add-in

    -> Now, open visual studio and create a new Qt project as described in here and then

    -> Right click on a header file that contains the Q_OBJECT macro you should find something like below. Copy these commands into your project.

    -> Replace the header file name with yours in the 'Command Line' command

    -> compile once and that should generate moc_xxxxx.cpp files, include them in your project.

enter image description here

  1. For future reference, if you create a Qt project in VS using this plugin you should have these commands automatically added

Exclude .h file from the project and include it again - moc_.cpp will appear in the "Generated Files", and linking errors are disapeared.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top