can the moc compile a class flagged as Q_OBJECT in Visual Studio Express 2017 ?



  • I wrote a simple class herited from QObject in my main cpp file but can't instanciate it in the main.

    note that everything is compiling fine if I only define the class Anchor but don't use it.
    Here's the code

    #include <QtGui/qguiapplication.h>
    
    #include <QtQml/qqmlengine.h>
    #include <QtQml/qqmlapplicationengine.h>
    
    #include <QtCore/qplugin.h>
    #include <QtCore/qcompilerdetection.h.h>
    #include <QtCore/qvariant.h>
    #include <QtCore/qmetaobject.h>
    
    #include <QtQuick/qquickview.h>
    
     
    class Anchor :public QObject
    {
         Q_OBJECT
         Q_PROPERTY(QString testStr READ getStr WRITE setStr NOTIFY strChanged)
    public:
         Anchor(){   TRACE_DEBUG("Anchor CTOR")   }
         Q_INVOKABLE void clicked(){
               TRACE_DEBUG("I ain't doin nothin")
         }
    };
    
    int main(int argc, char** argv){
    
         Anchor anchor;
         return 0;
    }
    

    Here are the errors :
    the little
    E2512 : the argument of functionality test macro has to be a simple identifier 2 times
    and
    LNK2001 : unresolve extern symbol "public virtual int __cdecl Anchor ::qt_metacall((enum QMetaObject ::Call,int,void**)(?qt_metacall@Anchar@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

    LNK2001 : unresolve extern symbol "public virtual struct QMetaObject const* __cdecl Anchor ::metaObject(void) const"(?metaObject@Anchar@@UEBAPEBUQQMetaObject@@XZ)

    and another one about metacast, same style.

    So I guess that my solution/project can't deal with meta objects ? I've seen that it's not obvious that Visual Studio Express (2017) can use the MOC. Is it possible ?

    if(possible){How(?);}
    

    ps : I would like to use another IDE, use CMake, code on linux. But I can't. That's visual studio and I'm lucky to use 2017 instead of 2010


  • Moderators

    @Quentin91
    It seems that the moc output source file isn't compiled into your executable.
    Do you have the Qt VS Addin installed?



  • @raven-worx I don't think so. i will try to download it and install it on my dev computer. But I've seen that the Express version of VS doesn't support it... probably.

    I'll try it, then try to use qmake and maybe a this point I'll get the professionnal version.

    Also, I'll edit my question, I'm using QtCreator to compile some QML. Maybe I can use it for the Meta Objects too ?


  • Moderators

    @Quentin91 said in can the moc compile a class flagged as Q_OBJECT in Visual Studio Express 2017 ?:

    But I've seen that the Express version of VS doesn't support it... probably.

    plugin support was added in recent versions of VS Community.


Log in to reply
 

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