Visual Studio 2013 and Qt5: QTDIR set too late

user2368140 picture user2368140 · Feb 24, 2015 · Viewed 8.9k times · Source

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?

Answer

Lichtkarussell picture Lichtkarussell · Mar 20, 2015

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.