1
在我的文本编辑器应用程序中,我将用户字体格式选择保存为首选项。Qt:不通过信号和插槽机制恢复首选项
信号和槽首先被设置在构造,然后将偏好被读取如在下面的代码:
构造:
boldAction->setCheckable(true);
italicAction->setCheckable(true);
underlineAction->setCheckable(true);
fontSizeSelector->setCheckable(false);
connect(boldAction,SIGNAL(changed()),this,SLOT(bold()));
connect(italicAction,SIGNAL(triggered()),this,SLOT(italic()));
connect(underlineAction,SIGNAL(triggered()),this,SLOT(underline()));
ReadUserPreferences():
void TextEditor::readUserPreferences()
{
QSettings userPreferences(QSettings::NativeFormat,QSettings::UserScope,ORGANIZATION_TITLE,APPLICATION_TITLE);
this->boldAction->setChecked(userPreferences.value("appearance/bold").toBool());
this->italicAction->setChecked(userPreferences.value("appearance/italic").toBool());
this->underlineAction->setChecked(userPreferences.value("appearance/underline").toBool());
//other code.
}
现在,在readPreferences函数中,当boldAction->setChecked(true);
,由于信号和时隙机制已经被定义,文本不应该变为粗体?如果是这样,那么为什么它不在我的应用程序上工作?大胆的功能本身工作得很好。
有没有比我所做的更好的方式做到这一点?感谢您的帮助