Results 1 to 3 of 3

Thread: Bug in Qt Visual Studio Add-in

  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    304
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Bug in Qt Visual Studio Add-in

    I am using the Qt Visual Studio Add-in version 2.5.2 rev 1 for Microsoft Visual Studio 2015. i have done a fresh install of the add-in after removing it completely from Visual Studio, but the bug I am seeing still persists.

    Somewhere in the chain of things that happens when a project is built, a "qtvars_x64_Debug.props" (or "Release") file is created by the QtMSBuild macros that are part of the add-in. This is an XML file that contain an XML element tag with a syntax error:

    Qt Code:
    1. 1>C:\...\QtWidgetsApplication1\QtWidgetsApplication1\x64\Debug\qmake\qtvars_x64_Debug.props(8,1): error MSB5016: The name "QMake_QMAKE_TARGET.arch_" contains an invalid character ".".
    To copy to clipboard, switch view to plain text mode 

    The offending line is:

    Qt Code:
    1. <QMake_QMAKE_TARGET.arch_>x86_64</QMake_QMAKE_TARGET.arch_>
    To copy to clipboard, switch view to plain text mode 

    It stops the build dead. If I edit the line to replace the "." with "_", the build will then proceed without errors, but the next time I do a Rebuild All or make any change to the project, the file gets re-created and I am back to the same dead end.

    This happens with any project using the add-in and MSBuild, including a freshly-created Qt project with no modifications, just clicking "build" after the new project wizard exits.

    I have looked everywhere to try to find the command that is generating these files, and can't find it. The add-in puts a bunch of parameter and command files in C:\Users\...\AppData\Local\QtMSBuild but there is nothing obvious there, but I admit I do not understand the MSBuild macro language. Nothing in the mkspecs for my Qt version (5.14.2) either.

    Has anyone see this? Have you seen it in newer version of MSVC (2017, 2019, or 2022)?

    Thanks for any information.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    304
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Bug in Qt Visual Studio Add-in

    After several hours studying the QtMSBuild scripts, I was able to find where the problem occurs, but not why. So I kludged a workaround.

    The qt_vars.targets file (in the QtMSBuild directory) is loaded by the MSVC .vcxproj project file. In the targets file, this command is issued to create a temporary file named "props.txt". I guess this dumps the contents of the project's .pro file:

    Qt Code:
    1. qmake -query >props.txt
    To copy to clipboard, switch view to plain text mode 

    props.txt starts with this and contains all sorts of Qt-related path names and parameters in a "Key:Value" format:

    Qt Code:
    1. QMAKE_TARGET:x86_64
    2. QMAKE_TARGET.arch:x86_64
    3. QT_SYSROOT:
    4. QT_INSTALL_PREFIX:
    5. ...
    To copy to clipboard, switch view to plain text mode 

    This file then is parsed and its contents converted into the MSBuild XML that is then executed during the build. Except it doesn't, because the "QMAKE_TARGET.arch" string gets converted into an invalid XML element tag (containing a ".").

    So my workaround / kludge was to add some commands in this qt_vars.targets file to edit the props.txt file (using sed) and replace the "QMAKE_TARGET.arch" string with "QMAKE_TARGET_arch". This modified props.txt gets parsed and executed without problems by MSBuild with no apparent effect on the result - the project compiles, links, and runs just fine.

    If you run into this same problem, here are the relevant lines from qt_vars.targets, starting around line 100. My changes are between the Begin and End bug fix comments:

    Qt Code:
    1. <!--// Run qmake: query properties -->
    2. <PropertyGroup>
    3. <Cmd><![CDATA[("$(QtToolsPath)\qmake.exe" -query) 1> props.txt 2> NUL]]></Cmd>
    4. </PropertyGroup>
    5. <Exec WorkingDirectory="$(QtVarsWorkDir)" Command="$(Cmd)"/>
    6.  
    7. <!-- Begin bug fix: Replace QMAKE_TARGET.arch in props.txt with QMAKE_TARGET_arch to avoid parsing error in MSBuild -->
    8.  
    9. <!-- Use sed to edit the line, then copy the temp file back into props.txt -->
    10. <PropertyGroup>
    11. <Sed><![CDATA[("$(QtMsBuild)\sed.exe" -f "$(QtMsBuild)\script.sed" props.txt >foo.txt) ]]></Sed>
    12. </PropertyGroup>
    13. <Exec WorkingDirectory="$(QtVarsWorkDir)" Command="$(Sed)"/>
    14.  
    15. <PropertyGroup>
    16. <CopyFoo><![CDATA[(copy /Y foo.txt props.txt 1> NUL) ]]></CopyFoo>
    17. </PropertyGroup>
    18. <Exec WorkingDirectory="$(QtVarsWorkDir)" Command="$(CopyFoo)"/>
    19.  
    20. <!-- End bug fix -->
    21.  
    22. <ReadLinesFromFile
    23. File="$(QtVarsWorkDir)\props.txt">
    24. <Output TaskParameter="Lines" ItemName="QMakeQueryResult"/>
    25. </ReadLinesFromFile>
    To copy to clipboard, switch view to plain text mode 

    The sed script (in script.sed) is very simple. I put the script file and a copy of sed.exe into the QtMSBuild directory for convenience:

    Qt Code:
    1. s/QMAKE_TARGET.arch/QMAKE_TARGET_arch/
    To copy to clipboard, switch view to plain text mode 


    ----------------------------------------
    Edit: *&!#**& Each time Visual Studio starts, it replaces the files in the QtMSBuild directory with the original versions, thereby wiping out my changes to the qt_vars.targets file. I am determined that I will be the one who wins this battle.
    Last edited by d_stranz; 27th May 2022 at 01:20.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,246
    Thanks
    304
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Bug in Qt Visual Studio Add-in

    Follow-up: I have won the battle, for now. I discovered where Visual Studio stores the original versions of the files used by the add-on, and replaced the original version of qt_vars.targets with my modified one. Now when Visual Studio starts up and the add-on loads, it copies my modified file into the QtMSBuild directory.

    Of course, this will only work until the next update of the add-on, but if that has the same bug, I know what to do.

    Hah! Take that, Microsoft!
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 5th March 2021, 23:57
  2. Using Qt 5.4.1 Visual Studio 2013 libs in Visual Studio 2010
    By ^NyAw^ in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2015, 11:20
  3. ms visual c++ compile without ms visual studio
    By zzz9 in forum General Programming
    Replies: 2
    Last Post: 12th August 2012, 21:29
  4. Visual Studio Plugin (1.1.6) crashes Visual Studio (2010)
    By mboeni in forum Installation and Deployment
    Replies: 0
    Last Post: 11th October 2010, 17:46
  5. Qt Visual Studio Add-in for Visual Studio 2010??
    By jiapei100 in forum Installation and Deployment
    Replies: 3
    Last Post: 5th July 2010, 14:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.