我有点新手,我无法让保存和加载工作。该程序有一些单选按钮和旋转框,我希望能够将这些位置和值保存到文件中,并能够稍后再次打开它。这是节省:
void MainWindow::on_saveButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Salvesta Projekt"), "",
tr("Latid Pindalaks (*.lp);;All Files (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_8);
QByteArray MyArray = MainWindow::saveState();
out << (MyArray);
}
}
这是加载
void MainWindow::on_loadButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Ava Projekt"), "",
tr("Latid Pindalaks (*.lp);;All Files (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::information(this, tr("Pole võimalik faili laadida"),
file.errorString());
return;
}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_8);
in >> (MyArray);
MainWindow::restoreState(MyArray);
}
}
我知道我做错了什么,所以一个很好的例子将不胜感激。