使用 QApplication::applicationDirPath 调用重载'arg(QString (&)())'时,调用是不明确的,为什么?
Call of overloaded 'arg(QString (&)())' is ambiguous when called using QApplication::applicationDirPath, why?
QString msgText = QString("The file has been saved at %1sysconf.xml").arg(QApplication::applicationDirPath);
给了我上面的错误。我以前用过.arg()
,所以我想知道为什么它会给我这个错误?我代码中的所有其他.arg()
都可以正常工作。
解释
QApplication::applicationDirPath
是一个静态成员函数,要获得你要找的值,你必须这样对待它,因此;你必须调用该函数。
目前您正在尝试将函数指针传递给QString::arg
,并且由于编译器找不到适合此类构造的重载,因此会引发诊断。
解决方案
QString msgText = QString(...).arg(QApplication::applicationDirPath ());
注意:请参阅QApplication::applicationDirPath
后添加的()
。
尝试实际调用该函数:
QString msgText = QString("The file has been saved at %1sysconf.xml").arg(QApplication::applicationDirPath());
请注意应用程序目录路径后面的"(("。
根据这一点,您将传递一个指向静态成员函数applicationDirPath
的指针,并且arg
有几个重载,它们都不接受这样的 poitner。您的编译器似乎发现了函数指针到参数类型的多次转换arg
这些参数类型被重载并感到困惑。你的意思是:
QString msgText = QString("The file has been saved at %1sysconf.xml")
.arg(QApplication::applicationDirPath());
// ^^--!!
相关文章:
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 为什么调用不明确的 ctor 时没有编译时错误?
- G++ 错误:重载的"abs(无符号 int)"的调用不明确
- 如果存在具有不同参数的继承成员,为什么对 C++ 结构函数的调用不明确?
- 错误:重载'stoi(nlohmann::basic_json<>::value_type&)'的调用不明确
- 构建 castalia 时出错:重载函数的调用不明确
- 错误:重载的"abs(double)"调用不明确
- 结构构造函数调用不明确
- 错误:对重载函数的调用不明确
- 对重载'swap(char&, char&)'的调用不明确
- 对可变模板函数的调用不明确
- C++ 编译错误:重载的"<function_name>(char*&)"调用不明确
- VS2010中具有list_of的调用不明确
- 为什么这个运算符=调用不明确
- 为什么对重载函数的调用不明确
- C++中重载运算符函数对构造函数的调用不明确
- 为什么这些重载函数调用不明确
- 重载write(int)的调用不明确
- 带有重载r值引用函数的调用不明确
- 传递0而不是1时,sfinae调用不明确