Results 1 to 5 of 5

Thread: Invoking MOC w/MSVS + Qt Visual Integration

  1. #1
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Invoking MOC w/MSVS + Qt Visual Integration

    I'm running Microsoft Visual Studio 2005 (2.0.50727) with Qt Visual Studio Integration 1.2.2
    I have a legacy application written by a person who is unavailable.
    I added a new class by adding a new *.h header file and a new *.cpp C++ file. The new class was based on QObject, and the header file dutifully included the Q_OBJECT macro at the top of the class definition, along with some slots and signals.

    When I compiled my project, I got a lot of error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall... errors. Examining the build output, I realized that MOC had been run on the original files, but not on my new file. There was no *_moc.cpp file generated for my new class.

    I manually ran MOC.exe on my new header file, and manually inserted the resulting moc file into my project. This compiled and ran perfectly.

    So my question is: what am I doing wrong to cause Qt Integration to fail to automatically run MOC on my new class?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Invoking MOC w/MSVS + Qt Visual Integration

    See Tools->Options->Qt->General->AutoUpdateMocSteps.

    PS. I'm not sure since which version was this option added, but try checking it out.
    J-P Nurmi

  3. #3
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Invoking MOC w/MSVS + Qt Visual Integration

    Quote Originally Posted by jpn View Post
    See Tools->Options->Qt->General->AutoUpdateMocSteps.
    Thanks, but alas, it was already set to TRUE.

    As a work-around, I opened up the properties for the *.h file in question, went to Configuration Properties|Custom Build Step|General, and entered the following:

    Command line: $(QTDIR)/bin/moc -o $(InputName)_moc.cpp $(InputPath)
    Description: Running MOC on $(InputPath)
    Outputs: $(InputName)_moc.cpp

    But it would be nice if the Qt Integrator would notice the presence of the Q_OBJECT macro and automatically add this.

  4. #4
    Join Date
    Nov 2007
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Invoking MOC w/MSVS + Qt Visual Integration

    HI!

    I saw this question which did not seem to have been closed. I was searching for the same problem after a re-install after win crash. I have Visual .net 2003 and qt4.3.2 and the vs-integration 1.3.2

    I added a *.h with a QOBJECT and no moc stage was created.

    in previous version of the VS integration there was a moc button but no more. But as I found somewhere out there this is the trick:

    Actually so easy, just open the *.h file edit it (add a space for example) and save, then like magic the moc stage is there.

    /Anders

  5. #5
    Join Date
    Aug 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Invoking MOC w/MSVS + Qt Visual Integration

    The sequence to get auto moc support is finicky but it does work if you add the .h file under Source Files by right-clicking in the solution explorer and choosing Add -> Existing Item. This must be done before the first build after the corresponding .cpp file is added. That was the mistake I made. If moc support is enabled you will see "compile" as a right-click menu item for the .h file. Also looking at the properties you will see a dependencies rule that runs moc.

    I am using Qt studio add in version 1.1.5 and VS studio 2008

Similar Threads

  1. Qt configure with msvc.net
    By jivanr in forum Installation and Deployment
    Replies: 1
    Last Post: 11th June 2007, 08:17
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  3. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.