【发布时间】:2014-01-23 22:53:27
【问题描述】:
我正在尝试创建一个函数,当用户想要使用 QPushButton 将名称恢复为默认值时替换 QLineEdit 中的文本。
这是“保存”代码的地方。
`//Must get information in the DB
lineditPlayerName = new QLineEdit("Nouveau Profil");
nameAsDefault = new QString(lineditPlayerName->text());
languageAsDefault = new QString(comboBoxlanguage->currentText());`
这是我用来将值更改回默认值的函数
//This code works
void ProfileManager::revertName(){
lineditPlayerName->setText("nameAsDefault");
btnRevertName->setEnabled(false);
}
但我需要这样:
//This code does'nt
void ProfileManager::revertName(){
lineditPlayerName->setText(NameAsDefault);
btnRevertName->setEnabled(false);
}
我无法让它工作它给了我这个错误: 调用 'QLineEdit::setText(QString*&)' 没有匹配的函数
谢谢
【问题讨论】:
-
你真的需要动态分配你的QString吗?在 Qt 中,我几乎不需要这样做。
-
我已经在线阅读了一个教程,这就是我所拥有的所有形式......如果你能解释为什么我不需要这样做,我将不胜感激,你能解释一下如何去做。
-
你想要一个
QString nameAsDefault类的成员,而不是QString * nameAsDefault(指向字符串的指针)。然后,您只需编写nameAsDefault = lineeditPlayerName->text()即可设置它。
标签: c++ qt qstring qcombobox qlineedit