Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt - Visual studio 2010 , Moc changing CPP file causes link error. forces me to rebuild moc files
Forum Updated to NodeBB v4.3 + New Features

Qt - Visual studio 2010 , Moc changing CPP file causes link error. forces me to rebuild moc files

Scheduled Pinned Locked Moved Qt Creator and other tools
18 Posts 4 Posters 14.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #9

    Typically you have somewhere the generatedfiles stored. Delete the ones, which you think need moc'ing.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jolson
      wrote on last edited by
      #10

      I've tried that, the problem is if I delete them the files are not re-created. which requires me to regenerate the vcproj. The Moc’ing xxx.h… is displayed for each header but nothing is generated.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #11

        OK. You need to check then the "Outputs" property for your header files then. It typically sais something like "./generatedfiles/" with some macros attached.

        Other solution could be to remove the files in question from your project. Beware, to make a backup first. But that is probably what you mean with regenerate .vproj, isn't it?
        I had to do this recently, but it works ever since.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jolson
          wrote on last edited by
          #12

          My outputs property for the header is
          $(ConfigurationName)\moc_%(Filename).cpp;%(Outputs)

          When I say regenerate I open the project file (.pro) from the qt plug in which asks me if I want to recreate the vcproj file.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #13

            I do not use .pro files for msvc. Respectively, only for getting the project struture to qt creator on linux.

            Can you trace the output? Are the files created where they are supposed to be created?

            In msvc 2005 I removed (not delete!) the files and added them as existing files again. That cured recently my problem.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #14

              Changing mainwindow.cpp should not require moc_mainwindow.cpp to be recompiled. The moc file contains only stuff created out of the header file.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jolson
                wrote on last edited by
                #15

                I figured out why I am having an issue, the problem is when I compile the moc_mainwindow.cpp exclude from build property is set to yes. So the next time I try to compile I get link errors.

                Any idea why the exclude from build prop is getting set to yes?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #16

                  The exclude from build is handled by vs addins I assume or it must be handled by msvc itself.
                  In msvc 2005 it looks like this:
                  !http://db.tt/1OzWlfNv(GeneratedFilesSection)!
                  This is for compilation in debug mode. The release mode shows the "excluded from build" stop sign at right. The debug section does not because that is debug mode. When switching to release mode it will be the other way around.
                  As explained above I had an issue there as well recently. I was removing from the project (do not delete the files) the adequate header, source and ui files and adding them to the project again with "add existing files". This procedure cured the problem.
                  Before that I was fiddling around with the properties but that confused only the whole build process even more.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jolson
                    wrote on last edited by
                    #17

                    Removing and re-adding the files didn't help. For now I can live with this, when I'm finished with my current project I think I will try a fresh install.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      phyatt
                      wrote on last edited by
                      #18

                      I got stuck in this same problem earlier today. I tried build clean on my project and started getting the "c1xx : fatal error C1083: Cannot open source file: 'Release\moc_xxxx.cpp': No such file or directory" errors.

                      After much frustration with vs2010, I figured two things out:

                      I could get the moc_xxxx.cpp files to come back using the "Restore previous versions" options that came with my version of Windows. Every time you update windows, it takes a snapshot of your recently changed files and saves it on your harddrive.

                      After getting it to that point, I also found another "fix" but this is more of a hack than a fix. For every .h file that you want to force Moc'ing for, (so any of them with a Q_OBJECT macro in them) you can tell visual studio to explicitly build the .h file (right click on the file and choose compile, or press Ctrl-F7 while in the .h file).

                      Then the next time you build, it can find the Moc'ed file and the error goes away.

                      I hope that helps someone.

                      It would be nice if there was an option built into the Qt menu on the VS plug-in that could do that for you (such as "Regenerate All Moc Files") or if it could notice that the moc files don't exist and built them so that you can recover after a build clean.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved