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);
,由於信號和時隙機制已經被定義,文本不應該變爲粗體?如果是這樣,那麼爲什麼它不在我的應用程序上工作?大膽的功能本身工作得很好。
有沒有比我所做的更好的方式做到這一點?感謝您的幫助