Is there anyway to get the windows style path to the directory containing the .pro
or convert what is stored in _PRO_FILE_PWD_
to a Windows style path ?
I have an issue with the _PRO_FILE_PWD_
variable in Qmake where it returns a unix style path on windows.
e.g c:/foo/bar
instead of c:\foo\bar
This is proving a problem where the path is being used as part of a post link step.
QMAKE_POST_LINK += copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll $${_PRO_FILE_PWD_}/bin/;
I use the .pro
file to create a Visual Studio project and I can see that if I manually change the forward slashes to back slashes in VS that everything is copied fine without any errors.
I get the following error in Visual Studio if I don't correct the path.
PostBuildEvent:
1> Description: copy /y C:\Qt\4.8.3\bin\QtCore4.dll E:/foo/build/win32//bin//;
1> The syntax of the command is incorrect.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "copy /y C:\Qt\4.8.3\bin\QtCore4.dll E:/foo/build/win32/bin/;
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :VCEnd" exited with code 1.
Solution
Very simple solution thanks to Roku by adding escaped double quotes around the path using / characters.
MAKE_POST_LINK +=
copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll \"$${_PRO_FILE_PWD_}/bin/\";
Note for addingi multiple copy commands you must seperate them with the ampersand the semicolon doesn't work.
e.g.
MAKE_POST_LINK +=
copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll \"$${_PRO_FILE_PWD_}/bin/\" &
MAKE_POST_LINK +=
copy /y $$[QT_INSTALL_BINS]\\QtGui4.dll \"$${_PRO_FILE_PWD_}/bin/\";
$$shell_path()
will convert the slashes to local system format, so:
QMAKE_POST_LINK += copy /y "$$shell_path($$QT_INSTALL_BINS/QtCore4.dll)" "$$shell_path($$_PROD_FILE_PWD_/bin)"
Oddly enough, escaping the double quotes works for the destination file but not the source.
i.e. this works:
copy C:\dev\playground\qt\SampleProject\debug_qt.conf "C:/dev/playground/qt/build-SampleProject-Qt_8_4_6_Desktop-Debug/qt.conf"
but this doesn't:
copy "C:/dev/playground/qt/SampleProject/debug_qt.conf" "C:/dev/playground/qt/build-SampleProject-Qt_8_4_6_Desktop-Debug/qt.conf"
As already noted, $$shell_path(path)
works under Qt5.
On Qt4, $$replace(string, old_string, new_string)
can be used instead.
Example:
MY_PATH = $$PWD
message($$replace(MY_PATH, /, \\))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With