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

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!")

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.

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

How to always compile a file?

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.

Qt ui file does not compile in to C++ header

I've created a Qt Application project in Visual Studio 2010. It contains the following files
Form Files
mainwindow.ui
Header Files
mainwindow.h
Source Files
mainwindow.cpp
It also uses a generated codefile called ui_mainwindow.h. From what I've been able to discern, this file should be regenerated in response to changes made to the .ui file. However if I open the ui file in Designer and make a change, no change appears in the application.
I have to go to Form -> View Code -> Save As in Qt Designer and save the ui_mainwindow.h file manually.
.ui file should have custom build tool defined to use uic on it and produce appropriate ui_*.h file.
Custom build tool command line may look like this:
uic.exe "$(InputPath)" -o "ui_$(InputName).h"
Also, in order to properly detect dependencies and to Clean command remove generated file, add ui_$(InputName).h to Custom Build Tool Outputs.
Don't forget to make the changes for all Configurations and Platforms.
Although, the right way to do this would be to create appropriate .pro file and then generate Visual Studio project with qmake -tp vc project.pro. All compiler and linker settings should be adjusted in .pro file, not in Visual Studio project that should be regenerated after each change of .pro file.
i mean no offense but have you saved the .ui file before running the project?
when i need to edit the ui files, i change them with the designer and when i want to run it, it will recompile/moc/whatever the changed ui file and their .h/.cpp file as well.

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?