6

Everything works with Qt in MSVC2013, except one thing: the DLLs are not found, because $(QTDIR) is not defined, when the local debugging environment is set.

My debugging environment settings:

PATH=$(QTDIR)\bin%3b$(PATH)

My .user file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
    <QTDIR>C:\Qt\Qt5.4.1\5.4\msvc2013</QTDIR>
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LocalDebuggerEnvironment>PATH="$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b"$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
    <QTDIR>C:\Qt\Qt5.4.1\5.4\msvc2013</QTDIR>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LocalDebuggerEnvironment>PATH="$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
  </PropertyGroup>
</Project>

I don't know why, but the $(QTDIR) variable is not available to LocalDebuggerEnvironment.

It works with following debugging environment settings:

PATH=C:\Qt\Qt5.4.1\5.4\msvc2013\bin%3b$(PATH)

Is it possible to make Visual Studio handle this properly or do I have to enter the path manually?

3 Answers3

7

It seems Visual Studio parses the lines from top to bottom, so with your code...

<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>
<QTDIR>C:\Qt\Qt5.4.1\5.4\msvc2013</QTDIR>

...the variable $(QTDIR) is defined in the second line, and is cannot be used in the first line.

Simply switch the order so that the variable is defined before it is used:

<QTDIR>C:\Qt\Qt5.4.1\5.4\msvc2013</QTDIR>
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3b$(PATH)</LocalDebuggerEnvironment>

Note: Visual Studio only reads the .user file at startup, so you need to (re-)start Visual Studio after editing the file.

  • I've tried this already, but does not work. Is it possible to check which value $(QTDIR) has? –  Mar 20 '15 at 21:58
  • For me (MSVS2013, QT5.3.1 and 5.3.2), the automatically generated file had the same order as yours, and changing it helped. Did you change it for all groups? You can see the value of $QTDIR in many places, for example when editing a project property (e.g. General->Output dir->Edit...). When editing, "Macros>>" opens a searchable list of all available variables. – Lichtkarussell Mar 20 '15 at 22:00
  • Yes, I changed both entries. Do I have to do anything else? –  Mar 20 '15 at 22:06
  • Oh, restarting Visual Studio solved it! But why is QTDIR always added twice to the debugger environment? –  Mar 20 '15 at 22:23
  • Looking at your .user file, the propery group for Release|x64 doesn't even have a setting for QTDIR at all! The vs add-in is supposed to put that in for you, but sometimes it doesn't. I have no idea why. If it's not specified in the .user file, Qt falls back to some mysterious path and I have no idea where it gets it. Does anyone here know? – Ph0t0n Jun 08 '16 at 00:51
2

Thank you for your discussion of this issue. I can report that it still is extant in Qt 5.8 / QT Extension for Windows Version 2.1.1 / Visual Studio 2015. The symptoms are that entering "$(QTDIR)\bin" (the location of the Qt DLLs) as a PATH folder spec in the VStudio Project property Debugger...Environment appears to work, but actually does not.

By "appears to work" I mean that if you click on the option to examine the Debugger Environment property, and the raw form of the Environment property looks like "PATH=$(QTDIR)\bin;...;$(PATH)" the VStudio editing dialog box will helpfully inform you that that PATH string evaluates to (e.g.) "PATH=D:\TechApps\Qt\5.8\msvc2015_64b\bin;..."--just as it should if the QTDIR macro was really present and had the correct value. This is cruelly deceptive!

Because, by "really doesn't work" I mean that the PATH as actually prepared for use when launching your Qt-dependent application from within VStudio doesn't see this macro. Your beautiful PATH string is reduced to "\bin;...". You can confirm this by temporarily copying your Qt DLLs from $(QTDIR)\bin into the folder of your application executable. Your application will launch correctly. And if you examine your PATH from within your program (using e.g. getenv("PATH") in c++, you will see that your program's PATH string is missing QTDIR. (That is, it is what it would be if QTDIR were the empty string.)

FWIW, another symptom of this problem is that if you examine the VStudio list of macros, $(QTDIR) is not in the list.

The solution described above (rearranging the elements in ...vcxproj.user) appears to solve the problem. When you move the definition(s) of QTDIR earlier in that file, the PATH string actually available to the application is correct, and $(QTDIR) is present in the list of macros known to Visual Studio.

HOWEVER, I don't know whether changing the "Qt VS Tools" options, or the "Qt Project Settings," in VStudio causes the .user file to be incorrectly overwritten again.

0

Changing (or re-selecting) the Qt Version in the solution (Change Solutions Qt Version) fixed the issue for me.

It took many seconds to re-initialize the projects and even then I don't believe the .user file updated until I did a build of the project.