Qt World Summit: Submit your Presentation

Unresolved external Error QtMetaObject

  • Hello Everyone,

    I'm trying to implement a simple server client application in QT. I'm using Visual Studio 2017.
    Here's the Header File to my client class.

    #pragma once
    #ifndef  Client_H
    #define	Client_H
    #include <QTcpSocket>
    class Client : public QObject 
    {	Q_OBJECT
    	 explicit Client (QObject *parent = 0);
    	 void Connect(); 
    public slots: 
    	QTcpSocket *socket; 

    and here's the code to Client.cpp

    #include "Client.h"
    Client::Client(QObject *parent) :
    void Client::Connect()
    	socket = new QTcpSocket(this); 
    	socket->connectToHost("", 8016); 
    	if (socket->waitForConnected(3000))
    		printf("Not Connected");

    as you can see it's pretty simple. In my Main.cpp i create an instance of the client class and then call the function Connect():

    Client Test;

    When building my project i get the following errors

    1>Client.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Client::metaObject(void)const " (?metaObject@Client@@UEBAPEBUQMetaObject@@XZ)
    1>Client.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Client::qt_metacast(char const *)" (?qt_metacast@Client@@UEAAPEAXPEBD@Z)
    1>Client.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Client::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Client@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

    I know that this Error means that the functions are declared but the definition is missing. I just don't know where to find these definitions and which file i have to link to get rid of these errors.

    Thank you

  • Lifetime Qt Champion

    Try to clean build folder (delete it) and rebuild all.

    can a default gui project run so we know VS is setup to link to Qt etc ?

    I would imagine we got more errors if no QtDLL was found.

  • @mrjj Hey thanks.

    Qt is already linked to VS and i already can run some other prjects
    the problem seems to only arise with this class

  • The definitions should be in the auto generated moc_Client.cpp which is also linked automatically.
    So I agree with clean and rebuild if other projects's mocing has no problem.

Log in to reply