具有Qt集成的c++中的参数无效
Invalid argument in c++ with Qt integration
我正试图用C++在eclipse中编写一个Qt程序,但我无法克服一个错误:
void MyTests::populateFirstList(){
Question* q = new Question;
q = this->ctr->getCurrent();
string s = this->ctr->toString(q);
}
Question是我定义的类型,带有toString(q)的行返回一个错误,表示参数无效。函数toString():
string Controller::toString(Question* q){
string s="";
string text = q->getText();
char c;
string::iterator it;
for (it= text.begin(); it != text.end(); it++)
{
if ((*it) == ' ') {
s+="n";
}
else {
s+=it;
}
}
return s;
}
为了安全起见,函数getCurrent():
Question* Controller::getCurrent(){
return this->question;
}
我不明白为什么会发生这种情况,因为函数toString()应该取一个指向Question的指针,而q是一个。我甚至不确定错误是由这些函数引起的还是更深层次的原因。谢谢你的帮助。
错误消息为:
invalid arguments ' Candidates are:
std::basic_string < char,std::char_traits < char >, std::allocator < char > >
toString(Question *) '
执行:运行QMake然后构建:)
最终您的错误来自行
} else s+=it;
最终应该是
} else s+=*it;
这可能不会解决问题,但我在这里看不到任何QT。为什么在编写QT应用程序时不使用QT对象?
void MyTests::populateFirstList(){
Question* q = this->ctr->getCurrent();
QString s = this->ctr->toString(q);
}
QString Controller::toString(Question* q){
QString s;
QString text = q->getText();
s = text.replace(" ","\n");
return s;
}
Question* Controller::getCurrent(){
return this->question;
}
相关文章:
- std::cin >>上的参数无效
- 结果失败或多个参数无效
- 错误:一元"*"的类型参数无效(具有"int"):使用 mergesort 计算
- 错误 带有模块的一元"*"(具有"int")的类型参数无效
- 由于调用 std::condition_variable 后参数无效而导致应用程序崩溃
- MPI_Iprobe:RMA 调用中的位移参数无效
- 推力::sort_by_key上的配置参数无效
- windres 致命错误:将输出写入时:参数无效
- 一元'*'的类型参数无效(有双精度)
- C++:传递给 C 运行时函数的参数无效
- 矢量模板参数无效
- 写入 -: 参数无效 } 时出错
- winsock2:recvfrom()函数以错误10022(参数无效)结束
- 模板参数的显式指定参数无效,该参数是 constexpr
- 模板参数无效
- 调用 getter 成员时的参数无效
- 模板模板参数中的参数无效
- 方法调用中的参数无效
- POSIX 计时器:参数无效
- C++类模板是一个模板:模板参数无效