Qmake, slashes, and custom build steps
-
Hi,
I'm using Qt 4.7.3, VS 2008, Windows XP.
I have a project file where the INCLUDEPATH variable includes a path that ends with a slash, e.g. like this: @ INCLUDEPATH += c:/mydir/@
This causes a problem with the generated custom build step that runs moc, as described "here ":http://www.qtforum.org/article/33308/problems-with-qmake-and-visual-studio.html (I'm not the OP).I dug a little deeper and found that the problem is this:
- When generating the VS project files, qmake replaces the forward-slash with a backslash. This results in a custom build step command-line that includes this switch:
@-I"c:\mydir"@ - When run, the Windows command interpreter interprets the backslash followed by double quotes as an escaped double quotes. This eventually ruins moc's command line - it's input-file parameter is now part of some other parameter that doesn't have closing quotes.
- When run with no input filename, moc tries to read from stdin. Since there's nothing there, all moc sees is an empty input file, resulting in the "No relevant classes found" message and no output file. I verified this by running the custom build step command-line in a 'cmd.exe' window - moc just waits for stdin.
My suggestion is to change qmake so it would detect include paths that end with a backslash, and add another backslash, e.g.: @-I"c:\mydir\"@ This way the quotes aren't escaped, and Windows is appeased :).
Another option is to remove trailing slashes from paths altogether, unless the path is the root of a drive, in which case you still need two backslashes.Now sure you can also just put a double slash in the project file to achieve the solution, but this puts the burden on the user, and when a problem occurs it's tricky to find the root of the problem (took me some time).
Thanks!
Alon - When generating the VS project files, qmake replaces the forward-slash with a backslash. This results in a custom build step command-line that includes this switch:
-
Or... you could not put the "/" at the end of the path. Generally for a folder path, the trailing slash is not needed. That should solve your problem.
-
bq. Generally for a folder path, the trailing slash is not needed.
Not entirely true: The trailing slash is indeed not mandatory for most folder paths, but it is mandatory for the root of a drive - e.g. "c:" isn't a legal path, so -I"c:" doesn't work, but -I"c:\" does.
-
Franzk: See "here":http://blogs.msdn.com/b/larryosterman/archive/2005/06/24/432386.aspx for some history.