QT MSVC2013/ vs2013 C2440: “初始化”: 无法从“initializer-list”转换为“***” 错误

本文解决了一个关于使用initializer-list初始化QVector时遇到的C2440错误问题,并提供了具体的修正方法,包括如何在pro文件中添加必要的宏定义。

错误信息

3> error C2440: “初始化”: 无法从“initializer-list”转换为“QVector<QPair<QString,QString>>”
3>          无构造函数可以接受源类型,或构造函数重载决策不明确
3> error C2440: “初始化”: 无法从“initializer-list”转换为“QVector<T>”
3>          with
3>          [
3>              T=QString
3>          ]
3>          无构造函数可以接受源类型,或构造函数重载决策不明确
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
注意,Windows下可能不容易编译通过,因为默认情况下,QVector没有打开接收initialize-list参数的构造函数。
需要在合适的pri文件或者$$QTCREATOR_SOURCES/qtcreator.pri中添加这几行

在pro文件中添加下面的配置

windows {
     DEFINES *= Q_COMPILER_INITIALIZER_LISTS
}
..\..\MainWindow.cpp(25): error C2440:初始化: 无法从“initializer list转换为“op::PoseExtractorCaffe” ..\..\MainWindow.cpp(25): note: “op::PoseExtractorCaffe::PoseExtractorCaffe”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(19): note: 可能是“op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)” ..\..\MainWindow.cpp(25): note: “op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)”: 无法将参数 3 从“const char [1]”转换为“const int” ..\..\MainWindow.cpp(28): note: 没有使该转换得以执行的上下文 ..\..\MainWindow.cpp(25): note: 尝试匹配参数列表“(op::PoseModel, const char [30], const char [1], int, std::vector<op::HeatMapType,std::allocator<op::HeatMapType>>, op::ScaleMode, bool)”时 ..\..\MainWindow.cpp(108): error C2664: “void op::PoseExtractorCaffe::forwardPass(const std::vector<op::Array<float>,std::allocator<op::Array<float>>> &,const op::Point<int> &,const std::vector<_Tp,std::allocator<_Tp>> &,const op::Array<float> &)”: 无法将参数 1 从“std::vector<cv::Mat,std::allocator<cv::Mat>>”转换为“const std::vector<op::Array<float>,std::allocator<op::Array<float>>> &” with [ _Tp=double ] ..\..\MainWindow.cpp(108): note: 原因如下: 无法从“std::vector<cv::Mat,std::allocator<cv::Mat>>”转换为“const std::vector<op::Array<float>,std::allocator<op::Array<float>>>” ..\..\MainWindow.cpp(108): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(39): note: 参见“op::PoseExtractorCaffe::forwardPass”的声明 ..\..\MainWindow.cpp(108): note: 尝试匹配参数列表“(std::vector<cv::Mat,std::allocator<cv::Mat>>, op::Point<int>)”时 ..\..\MainWindow.cpp(115): error C2059: 语法错误:“}” ..\..\MainWindow.cpp(115): error C2143: 语法错误: 缺少“;”(在“}”的前面) ..\..\MainWindow.cpp(118): error C2143: 语法错误: 缺少“;”(在“{”的前面) ..\..\MainWindow.cpp(118): error C2447: “{”: 缺少函数标题(是否是老式的形式表?) cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -O2 -MD -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DOPENPOSE_MODEL_PATH="\"C:/openpose-prosperity/models\"" -DNDEBUG -DQT_QML_DEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_MULTIMEDIA_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I..\..\..\untitled1 -I. -IC:\openpose-prosperity\include -IC:\opencv\build\include -I"C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.44.35207\include" -IC:\Qt\6.10.0\msvc2022_64\include -IC:\Qt\6.10.0\msvc2022_64\include\QtWidgets -IC:\Qt\6.10.0\msvc2022_64\include\QtMultimedia -IC:\Qt\6.10.0\msvc2022_64\include\QtGui -IC:\Qt\6.10.0\msvc2022_64\include\QtNetwork -IC:\Qt\6.10.0\msvc2022_64\include\QtCore -Irelease -I. -I/include -IC:\Qt\6.10.0\msvc2022_64\mkspecs\win32-msvc -Forelease\ @C:\Users\admin\AppData\Local\Temp\moc_MainWindow.obj.6924.1063.jom moc_MainWindow.cpp jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile.Release [release\MainWindow.obj] Error 2 jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile [release] Error 2 00:28:10: The command "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" terminated with exit code 2. 00:28:10: Error while building/deploying project untitled1 (kit: Desktop Qt 6.10.0 MSVC2022 64bit) 00:28:10: The kit Desktop Qt 6.10.0 MSVC2022 64bit has configuration issues which might be the root cause for this problem. 00:28:10: When executing step "Make" 00:28:10: Elapsed time: 00:07.
11-22
..\..\MainWindow.cpp(24): error C2039: "processButton": 不是 "Ui::MainWindow" 的成员 C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\ui_MainWindow.h(70): note: 参见“Ui::MainWindow”的声明 ..\..\MainWindow.cpp(49): error C2665: “op::PoseExtractorCaffe::PoseExtractorCaffe”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(19): note: 可能是“op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)” ..\..\MainWindow.cpp(49): note: “op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)”: 无法将参数 6 从“op::Point<int>”转换为“const bool” ..\..\MainWindow.cpp(55): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 ..\..\MainWindow.cpp(49): note: 尝试匹配参数列表“(op::PoseModel, std::string, int, initializer list, op::ScaleMode, op::Point<int>, op::Point<int>)”时 ..\..\MainWindow.cpp(87): error C3861: “displayImage”: 找不到标识符 ..\..\MainWindow.cpp(90): error C2440:初始化: 无法从“void”转换为“cv::Mat” ..\..\MainWindow.cpp(90): note: void 类型的表达式不能转换为其他类型 ..\..\MainWindow.cpp(93): error C3861: “displayImage”: 找不到标识符 ..\..\MainWindow.cpp(97): error C2556: “cv::Mat MainWindow::processFrame(cv::Mat &)”: 重载函数与“void MainWindow::processFrame(cv::Mat &)”只是在返回类型上不同 C:\Users\admin\Desktop\QT\untitled1\MainWindow.h(28): note: 参见“MainWindow::processFrame”的声明 ..\..\MainWindow.cpp(97): error C2371: “MainWindow::processFrame”: 重定义;不同的基类型 C:\Users\admin\Desktop\QT\untitled1\MainWindow.h(28): note: 参见“MainWindow::processFrame”的声明 ..\..\MainWindow.cpp(166): error C2039: "displayImage": 不是 "MainWindow" 的成员 C:\Users\admin\Desktop\QT\untitled1\MainWindow.h(12): note: 参见“MainWindow”的声明 cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -permissive- -Zi -MDd -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\untitled1.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_QML_DEBUG -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I..\..\..\untitled1 -I. -IC:\openpose-prosperity\include -IC:\opencv\build\include -I"C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.44.35207\include" -IC:\Qt\6.10.0\msvc2022_64\include -IC:\Qt\6.10.0\msvc2022_64\include\QtMultimedia -IC:\Qt\6.10.0\msvc2022_64\include\QtWidgets -IC:\Qt\6.10.0\msvc2022_64\include\QtGui -IC:\Qt\6.10.0\msvc2022_64\include\QtNetwork -IC:\Qt\6.10.0\msvc2022_64\include\QtCore -Idebug -I. -I/include -IC:\Qt\6.10.0\msvc2022_64\mkspecs\win32-msvc -Fodebug\ @C:\Users\admin\AppData\Local\Temp\moc_MainWindow.obj.7824.922.jom moc_MainWindow.cpp jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile.Debug [debug\MainWindow.obj] Error 2 jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile [debug] Error 2 00:52:55: The command "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" terminated with exit code 2. 00:52:55: Error while building/deploying project untitled1 (kit: Desktop Qt 6.10.0 MSVC2022 64bit) 00:52:55: The kit Desktop Qt 6.10.0 MSVC2022 64bit has configuration issues which might be the root cause for this problem. 00:52:55: When executing step "Make" 00:52:55: Elapsed time: 00:06.
11-22
..\..\MainWindow.cpp(28): error C2665: “op::PoseExtractorCaffe::PoseExtractorCaffe”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(19): note: 可能是“op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)” ..\..\MainWindow.cpp(28): note: “op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)”: 无法将参数 7 从“op::Point<int>”转换为“const bool” ..\..\MainWindow.cpp(35): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 ..\..\MainWindow.cpp(28): note: 尝试匹配参数列表“(op::PoseModel, const char [30], int, std::vector<op::HeatMapType,std::allocator<op::HeatMapType>>, op::ScaleMode, bool, op::Point<int>)”时 ..\..\MainWindow.cpp(116): error C2440: “<function-style-cast>”: 无法从“initializer list转换为“op::Matrix” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/core/matrix.hpp(118): note: 可能是“op::Matrix::Matrix(const int,const int,const int)” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix(const int,const int,const int)”: 无法将参数 3 从“uchar *”转换为“const int” ..\..\MainWindow.cpp(116): note: 没有使该转换得以执行的上下文 ..\..\MainWindow.cpp(116): note: 尝试匹配参数列表“(int, int, uchar *)”时 ..\..\MainWindow.cpp(117): error C2039: "copyFrom": 不是 "op::Array<float>" 的成员 C:\openpose-prosperity\include\openpose/core/array.hpp(21): note: 参见“op::Array<float>”的声明 ..\..\MainWindow.cpp(120): error C2039: "forward": 不是 "op::PoseExtractorCaffe" 的成员 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(16): note: 参见“op::PoseExtractorCaffe”的声明 cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -O2 -MD -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DOPENPOSE_MODEL_PATH="\"C:/openpose-prosperity/models\"" -DNDEBUG -DQT_QML_DEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_MULTIMEDIA_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I..\..\..\untitled1 -I. -IC:\openpose-prosperity\include -IC:\opencv\build\include -I"C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.44.35207\include" -IC:\Qt\6.10.0\msvc2022_64\include -IC:\Qt\6.10.0\msvc2022_64\include\QtWidgets -IC:\Qt\6.10.0\msvc2022_64\include\QtMultimedia -IC:\Qt\6.10.0\msvc2022_64\include\QtGui -IC:\Qt\6.10.0\msvc2022_64\include\QtNetwork -IC:\Qt\6.10.0\msvc2022_64\include\QtCore -Irelease -I. -I/include -IC:\Qt\6.10.0\msvc2022_64\mkspecs\win32-msvc -Forelease\ @C:\Users\admin\AppData\Local\Temp\moc_MainWindow.obj.5052.1171.jom moc_MainWindow.cpp jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile.Release [release\MainWindow.obj] Error 2 jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile [release] Error 2 00:17:11: The command "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" terminated with exit code 2. 00:17:11: Error while building/deploying project untitled1 (kit: Desktop Qt 6.10.0 MSVC2022 64bit) 00:17:11: The kit Desktop Qt 6.10.0 MSVC2022 64bit has configuration issues which might be the root cause for this problem. 00:17:11: When executing step "Make" 00:17:11: Elapsed time: 00:08.
最新发布
11-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值