title: Build Qt project with VS C++ Compiler 15.0 with C++17 to use WinRT APIs
body: <p>I would like to use libraries available via WinRT API (like <a href="https://docs.microsoft.com/en-us/uwp/api/" rel="nofollow noreferrer">these</a>) from my UWP application created using Qt 5.9.2 for UWP 64bit (MSVC 2017). I got Visual Studio Build Tool 2017 v15.5.7 installed on my machine. Windows 10 is my OS.</p>
  
  <p>Now, I have set up a kit as presented below.</p>
  
  <p><a href="https://i.stack.imgur.com/LODBH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LODBH.png" alt="UWP Kit setup"></a></p>
  
  <p>Then, in <code>.pro</code> file, I have added:</p>
  
  <pre><code>SOURCES += main.cpp
  
  INCLUDEPATH += $$PWD/cppwinrt/10.0.16299.0/
  DEPENDPATH += $$PWD/cppwinrt/10.0.16299.0/
  </code></pre>
  
  <p>I got <code>cppwinrt</code> from <a href="https://github.com/Microsoft/cppwinrt" rel="nofollow noreferrer">GitHub rep</a>.</p>
  
  <p>I just added some lines in <code>main.cpp</code> to test proper compilation:</p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include &lt;winrt/Windows.Devices.WiFi.h&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      WiFiAdapter wiFiAdapter;
  
      return a.exec();
  }
  </code></pre>
  
  <p>After running <code>qmake</code> and <code>build</code>, I am getting this error:</p>
  
  <blockquote>
    <p>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.12.25827\include\optional(15): fatal error C1189: #error:  class template optional is only available with C++17.</p>
  </blockquote>
  
  <p><a href="https://docs.microsoft.com/en-us/cpp/what-s-new-for-visual-cpp-in-visual-studio#c-compiler" rel="nofollow noreferrer">Windows documentation</a> clearly states that since v15.3 (once again, I have 15.5.7) C++ compiler accepts the <code>/std:c++17</code> flag. I have tried to pass it by adding one of these lines to <code>.pro</code> file:</p>
  
  <pre><code>CONFIG += c++1z
  # Or
  QMAKE_CXXFLAG=/std:c++17
  </code></pre>
  
  <p>None of them helped.....</p>
  
  <p>This is the detailed build command run by compiler:</p>
  
  <pre><code>cl -c -nologo -FS -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\uwp-test.vc.pdb -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQ_BYTE_ORDER=Q_LITTLE_ENDIAN -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP -DWINAPI_PARTITION_PHONE_APP=1 -DX64 -D__X64__ -D__x64__ -DQT_DEPRECATED_WARNINGS -DQT_CORE_LIB -I..\uwp-test -I. -I..\ne-patient-app-libraries\cppwinrt\10.0.16299.0 -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\include -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\include\QtCore -Idebug -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\mkspecs\winrt-x64-msvc2017 -Fodebug\ @C:\Users\NEUROE~2\AppData\Local\Temp\main.obj.11672.15.jom
  </code></pre>
  
  <p>What am I missing? What could solve the problem? Thank you!</p>