QtnProperty代码编译

代码地址

GitHub:QtnProperty


编译环境

IDE: Microsoft Visual Studio Community 2019, 16.11.15
Qt: 5.12.5_msvc2017, 32bit
OS: Windows 10 家庭版,21H2
Qt Visual Studio Tools: 2.8.1.6

修改综述

修改项目文件

VS导入pro文件时,QtnPropertyDemoQtnPropertyTests这两个项目无法加载,手动重新加载分别出现以下错误:

F:\Code\Library\QtnProperty\Demo\QtnPropertyDemo.vcxproj : error  : 无法加载具有重复项目项的项目: Demo.pef 作为 CustomBuild 且作为 CustomBuild 项类型包括在其中。
F:\Code\Library\QtnProperty\Tests\QtnPropertyTests.vcxproj : error  : 无法加载具有重复项目项的项目: PEG\test.pef 作为 CustomBuild 且作为 CustomBuild 项类型包括在其中。

查看QtnPropertyDemo.vcxproj,发现有两个ItemGroup内容是重复的,去掉一个就好了。

点击查看代码
  <ItemGroup>
    <CustomBuild Include="Demo.pef">
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Demo.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/QtnPEG.exe Demo.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PropertyEnum generator Demo.pef, PEG Headers Demo.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Demo.peg.cpp;Demo.peg.h;%(Outputs)</Outputs>
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Demo.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/debug/QtnPEG.exe Demo.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PropertyEnum generator Demo.pef, PEG Headers Demo.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Demo.peg.cpp;Demo.peg.h;%(Outputs)</Outputs>
    </CustomBuild>
  </ItemGroup>

类似的,QtnPropertyTests.vcxproj文件也去掉一个多余的ItemGroup

点击查看代码
  <ItemGroup>
    <CustomBuild Include="PEG\test.pef">
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PEG\test.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/QtnPEG.exe PEG\test.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PropertyEnum generator PEG/test.pef, PEG Headers PEG/test.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PEG\test.peg.cpp;PEG\test.peg.h;%(Outputs)</Outputs>
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PEG\test.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/debug/QtnPEG.exe PEG\test.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PropertyEnum generator PEG/test.pef, PEG Headers PEG/test.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PEG\test.peg.cpp;PEG\test.peg.h;%(Outputs)</Outputs>
    </CustomBuild>
    <CustomBuild Include="PEG\test2.pef">
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PEG\test2.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/QtnPEG.exe PEG\test2.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PropertyEnum generator PEG/test2.pef, PEG Headers PEG/test2.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">PEG\test2.peg.cpp;PEG\test2.peg.h;%(Outputs)</Outputs>
      <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PEG\test2.pef;%(AdditionalInputs)</AdditionalInputs>
      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        F:/Code/Library/QtnProperty/Internal/../bin-win32-msvc1929-i386/debug/QtnPEG.exe PEG\test2.pef
        if errorlevel 1 goto VCEnd
      </Command>
      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PropertyEnum generator PEG/test2.pef, PEG Headers PEG/test2.pef</Message>
      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">PEG\test2.peg.cpp;PEG\test2.peg.h;%(Outputs)</Outputs>
    </CustomBuild>
  </ItemGroup>

修改代码

  • 问题
    编译QtnPropertyDemo时,会报以下错误:

    1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xstddef(84,1): error C2678: 二进制“==”: 没有找到接受“const _Ty”类型的左操作数的运算符(或没有可接受的转换)
    
  • 原因
    使用std::equal_to时,类/结构体需要重载“==”运算符。

  • 解决方法
    MyColor中重载运算符“==”:

    点击查看代码
    Demo/AB/PropertyABColor.h | 7 +++++++
    1 file changed, 7 insertions(+)
    
    diff --git a/Demo/AB/PropertyABColor.h b/Demo/AB/PropertyABColor.h
    index 88e2995..304e5e7 100644
    --- a/Demo/AB/PropertyABColor.h
    +++ b/Demo/AB/PropertyABColor.h
    @@ -46,6 +46,13 @@ struct MyColor
         int red = 0;
         int green = 0;
         int blue = 0;
    +
    +    bool operator==(const MyColor& c) const
    +    {
    +      return red == c.red
    +        && green == c.green
    +        && blue == c.blue;
    +    }
     };
     
     using QtnPropertyMyColorBase = QtnSinglePropertyBaseAs<QtnPropertyQColorBase, MyColor>;
    

posted on 2022-08-04 14:45  OctoberKey  阅读(503)  评论(0)    收藏  举报

导航