How to always compile a file? - c++

I have a Qt project with QML files. Whenever I change these files, I have to manually right click the .qrc (resources) file and recompile it.
How do I tell visual studio to always compile a certain file, not only when it thinks it has changed?
(Here are similar questions others have asked for eclipse and flashdevelop)

I encountered the same problem while building qt apps using Qt Creator.(Especially while using QML files as resources.) I solved the problem using a little hack.
Created a batch file say touch.bat in my source directory.
This batch file contains a single line copy qml.qrc /B+ ,,/Y where qml.qrc is the resource file name.
Opened my project in QtCreator and went to Project->Build Steps->Add Build Step->Custom process step and entered touch.bat
Whenever the project build starts, the qml.qrc is touched. The build system thinks that qml.qrc is modified and builds it.
You can modify this hack for Visual Studio also.(I have not tried). Try adding touch.bat as a build step in Visual studio. The idea is to fool the build system to think that your .qrc is modified.
I guess this is a known bug which remains unresolved. Check this bug report.
Thanks.

Related

"Cannot open source file" error with existing file and correct path

I'm building some custom Qt components as a static library, but I can't get past the compilation phase.
My project is structured as follows:
Root:
- .h and . cpp files of the custom Qt components
- GeneratedFiles/Debug/ <-- here the MOC compiler puts the generated moc_*.cpp files ("Debug" is automatically deducted from the build configuration, so it's Release for release builds)
That's a pretty standard folder setup, but for whatever reason the compiler can't find only the moc files. Anything that is in the root folder builds just fine, but the moc files are not found. Please note, the moc_ files are generated just fine and exist where they're supposed to be, with the correct content. The problem seems to be in the evaluation of the path GeneratedFiles\Debug\moc_whatever.cpp.
Interestingly enough, if I move a moc file (say, moc_example.cpp) in the root folder and manually adapt the call to CL.exe to compile moc_example.cpp instead of GeneratedFiles\Debug\moc_example.cpp, the file gets built.
I'm using VS 2017 version 15.7.1, CL is version 19.00.24215.1 for x64 and I'll update the question with any other detail might be useful, just add ask in a comment.
So... Why is the compiler telling me those files do not exist?
I finally solved this rebuilding the directory structure in a new directory. Apparently, using WSL's git to check out repositories under Windows breaks something in the filesystem in a way that is invisible from Explorer or Ubuntu's command line, but that breaks the compiler (and Visual Studio's intellisense).
Checking out the repository with Git for Windows seems to avoid causing the same problem.

Project MESSAGE: You are running qmake on a generated .pro file. This may not work

When I'm loading a certain project using Qt Creator, I get this message repeated twice in the General Messages pane:
Project MESSAGE: You are running qmake on a generated .pro file. This may not work!
Project MESSAGE: You are running qmake on a generated .pro file. This may not work!
Screenshot:
This happens only on one of the projects (this project was created by a colleague, not me, so I don't know what's different about it).
What does this message mean? Is there something that should be fixed in the .pro file?
Project Message: usually indicates that the following text was printed in the qmake file using message(text).
In that case, your best hope is to grep for the message in all .pro files, find out where it comes from and asking your colleague what that message is supposed to mean if you can't figure it out.
Edit: I just found out that the Qt Visual Studio Integration puts this message in autogenerated qmake files. If you or your colleague are using the VS integration, you could remove that message if you do not intend to re-generate the .pro file. The message is basically there to tell you that you might have to adjust some things to make the project build correctly (which it seems to do in your case).
In that case, the code generally looks like this:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------
# This is a reminder that you are using a generated .pro file.
# Remove it when you are finished editing this file.
message("You are running qmake on a generated .pro file. This may not work!")

QCustomPlot in MSVS2012

I succeeded in building a program in visual studio 2012 that runs QT without the plugin. I included the QT include folder and manually added the libraries to the resources. And it compiled and ran.
Now I wanted to use QCustomPlot in the same way, without the QtAddin plugin. I tried multiple projects, where I added QCustomPlot's .h and .cpp and tried to compile, but it gives me tons of linker problems(http://pastebin.com/SWVXktBk). Can someone point me in the right direction?
Windows 7 x64, QT 5.4.1,
After hours, I found it.
As UldisK pointed, I had to moc the header.
I followed everything in here: http://ldmartin68.com/QTSetup4VSNET.html
In windows cmd
moc qcustomplot.h > moc_qcustomplot.cpp
then simply add the generated file to the project, and voila worked.
In the end you should have in the project:
the original qcustomplot.h
the original qcustomplot.cpp
the generated moc_qcustomplot.cpp

Qt moc failure without an error message

So I'm pretty new to Qt, and I've just inherited a project from someone else who is also new to Qt. He isn't around this week btw. We are using Visual Studio 2008, and have the latest version of Qt installed(4.6.2).
The project builds on my coworker's machine fine, and I can get the project from svn and build it directly. But under any other circumstances it refuses to build on my machine, and it doesn't give me much of an explanation why. Even if I just do a 'build clean' and then a 'build' it doesn't work. Any slight modification will make it fail.
When I try to build the entire project I get the error message:
1>Moc'ing MatrixTypeInterface.h...
1>moc: Cannot create
.\GeneratedFiles\Debug\moc_MatrixTypeInterface.cpp;.\GeneratedFiles\Debug\moc_matrixtypeinterface.cpp
1>Project : error PRJ0019: A tool
returned an error code from "Moc'ing
MatrixTypeInterface.h..."
The moc tool doesn't give any sort of error message as to why it isn't working, and I wasted most of yesterday trying to figure out why. I got the command that VS was using to call moc, and I entered in the command line myself. It didn't write anything to the screen.
Any ideas?
I finally found the answer. my coworker was back in the office today, and I used the build log off his machine to get his full moc command(about 4 lines long). Our moc commands were basically the same except at the very end. His command ended in:
-o ".\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp"
My command ended with:
-o ".\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp;.\GeneratedFiles\Debug\moc_matrixtypeinterface.cpp"
I checked the custom build step for that file, and removed the excess bit. After that the file compiled fine. I don't know how or why qt decided to add in this extra tidbit, but it did.
Thanks for your help guys. A couple of you suspected that it was a filesystem issue, and indeed a semicolon is not allowed in a windows filename. But I feel the root cause was Qt creating the wrong build string.
I'm accepting my own answer in the hope that it will help someone else.
It's most likely a filesystem error, you probably don't have a "GeneratedFiles" folder or don't have the correct permissions on it.
I have had issues where different versions of the moc and the add-in use "Generated" or "Generated Files" or "GeneratedFiles" for the folder. Check the settings on all the build steps.
Its possible that your .vcproj file is corrupted. I've had this issue before which resulted from having different versions of Qt and the Qt VS add-on ended up corrupting my .vcproj files. For a while, I had to manually fix the .vcproj file (My AdditionalDependencies="..." line was being swapped around and cut off for various header files that needed to be mocced, I was manually fixing these for every new header that needed to be mocced).
A clean reinstall of Visual Studios + Qt + Qt add-on ended up fixing this. Check your .vcproj file and see if its making sense.
Are you sure your file paths are correct and existing before moc runs? Since it appears that relative paths are provided to moc, I'd find out what moc's working directory is when it runs.
How was your .vcproj file generated? Was qmake used? Or cmake? Or was it by scratch?

visual studio 2008 isn't creating an .exe file when i build my project. any ideas why?

i'm new to visual studio and couldn't find anything on google about this. i know this is an extremely noobish question, but i can't seem to find any info for it.
the debug shows me whatever i write, and the build has no errors, so i know the code i'm writing is fine.
the release folder doesn't contain the .exe, even after i build it, rebuild, clean, etc.
it's a win 32 console project. the release folder contains the .obj files, the manifest, the build log, idb, pch and pdb files (one of each)
Some possible reasons:
Did you accidentally create a class library project? In that case the output would be a DLL and not an EXE.
Does the output window or the error list display any build errors? In that case you should first fix these, then build again.
Did you change the configuration of the project, so that the output (EXE) is created in a different folder than the default one?
There's not a whole lot of reason for people to be guessing... You said you can find the build log - the exact location of any output file will be in there. To make sure you're seeing the right build log file, the output window in VS will have a link to the file that particular build run created:
1>Build log was saved at "file://c:\DevTrees\cppTest\Debug\BuildLog.htm"
1>cppTest - 0 error(s), 2 warning(s)
If you're having trouble interpreting it, post the contents.
I had the same problem; the advice above to look closely at the output window was just what I needed - thanks. My confusion was because I was looking in solution>project>Debug when VS put it in solution>Debug.
The Release and Debug folders contain outputs from different build configurations.
If you look in Project properties, you will see an Output Folder setting in the Build section, and it will be different for each configuration. (You can see the setting for each configuration using the dropdown list at the top of the Project Properties window)
The Release folder will only get populated when you build the project in the Release configuration.
To switch to the Release configuration, use the dropdown list in the toolbar.
EDIT: I am describing the UI for C# projects. It may be different for native code.
Are you sure that your project type is correct? A class library project won't build an executable. It would need to be some sort of application project to create an executable.
I had the same problem. The compilation went fine, but no .exe was generated in the target folder (.\Debug).
The problem was actually that the file containing the main() function was called "FooProject.cpp". I renamed it to "main.cpp" and then the .exe was generated properly.
In other IDEs such as Eclipse CDT, you don't need to have your main file called "main.cpp" as long as you have a proper main() function. This is apparently not the case for Visual C++.