使用Qt集成的c ++中的参数无效

时间:2013-06-28 11:55:35

标签: c++ eclipse qt

我正在尝试使用C ++在eclipse中编写一个Qt程序,但我无法通过错误:

void MyTests::populateFirstList(){
    Question* q = new Question;
    q = this->ctr->getCurrent();
    string s = this->ctr->toString(q);
}

问题是我定义的类型,带有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 *) '

2 个答案:

答案 0 :(得分:1)

执行:运行QMake 然后建立 :)

答案 1 :(得分:0)

最终您的错误来自

        } else s+=it;

最终应该是

        } else s+=*it;

这可能无法解决问题,但我在这里看不到任何QT。编写Qt-App时为什么不使用QT-Objects?

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;
}