QT创建者错误(与操作员不匹配=)
QT Creator Error (no match for operator =)
每次构建代码时,我都会收到这个错误。我使用的是QT Creator 3.1(5.2.1版本)
错误:"operator+"不匹配(操作数类型为"QStringList"answers"const-char[2]")
这里有一段代码,希望它能有所帮助(星号行是错误突出显示的地方)
int main(int argc, char *argv[])
{
Shutdown = false;
QApplication a(argc, argv);
a.setApplicationName("aQtLow");
//Create default data paths if they don't exist
QDir Path;
**MainPath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation) + "/" + a.applicationName() + "Data";**
Path.setPath(MainPath);
问题是,自以来,您正试图将QStringList与QStrings连接起来
QStandardPaths::standardLocations(QStandardPaths::HomeLocation)
返回CCD_ 1。
您需要对要重用的元素进行gt处理,例如使用.first()
方法。你可以这样写:
MainPath=QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()+"/"+a.applicationName()+"/Data";
请注意,我只是在应用程序名称和"Data"之间添加了一个缺失的"/",因为我认为使用它更合乎逻辑,但如果您愿意,可以随意拒绝该编辑。
但是,由于您似乎对数据目录位置感兴趣,我建议使用QStandardPaths
:中的专用枚举
或者只使用会更好
QStandardPaths::DataLocation 9返回可以存储持久应用程序数据的目录位置。QCoreApplication::organizationName和QCoreApplication::applicationName附加到为GenericDataLocation返回的目录位置。
你可以这样写:
QDir Path(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first());
事实上,如果您希望避免.first()
调用,您可能会使用writableLocation()方法,如下所示:
QDir Path(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
=============================================
出于好奇,这也可能是一个替代方案:
QString QDir::homePath()[static]
或
QDirQDir::主页()〔静态〕
如下所示:
QDir Path = QDir::home();
Path.cd(a.applicationName() + "Data");
或
QDir Path(QDir::homePath() + "/" + a.applicationName() + "/Data");
如果这还不够的话,还有一个选择:
QDir Path(QCoreApplication::applicationDirPath + "/Data");
QStandardPaths::standardLocations返回QStringList。您应该在或使用foreach处使用QStringList::join或QSStringList::。Mb你想做其他事情,但我不知道是什么,因为变量MainPath太神秘了=)
- Qt SQLite没有查询或参数计数不匹配
- 模板参数推导失败,函数参数/参数不匹配
- 在使用累加时,C++中的运算符+不匹配
- C++ 与操作员不匹配<<
- 在 Arduino 上使用 sscanf 会导致与 const char * 不匹配,并且返回值始终相同,尽管输入值不同
- 与异常处理程序中的操作员<<不匹配
- 操作员不匹配<<
- C++"金钱<<分数"中的"操作员<<"不匹配
- 不断得到"与'操作员<<不匹配"C++
- 与操作员错误不匹配
- 与操作员'<<'不匹配 有人可以帮助解决无效功能错误吗?[C++]
- 为什么我会收到错误:"与 std 中的操作员>>不匹配"?
- C++ [错误] 与"操作员=="不匹配(操作数类型为"车辆"和"常量车辆")
- <thread>:操作员<不匹配
- Clang链接时间优化与替换的操作员新的原因不匹配的自由()/删除在valgrind
- 操作员<<不匹配
- 与操作员不匹配>>问题
- 操作员不匹配>>
- QT创建者错误(与操作员不匹配=)
- 井字 - 操作员*错误不匹配