QT 中我想在表中保存用户输入的信息,而程序重启后,数据会显示在表中,不会遗失!该如何做!
------解决方案--------------------
使用 QSettings.
- C/C++ code
void MainWindow::writeSettings() { QSettings settings("Moose Soft", "Clipper"); settings.beginGroup("MainWindow"); settings.setValue("size", size()); settings.setValue("pos", pos()); settings.endGroup(); } void MainWindow::readSettings() { QSettings settings("Moose Soft", "Clipper"); settings.beginGroup("MainWindow"); resize(settings.value("size", QSize(400, 400)).toSize()); move(settings.value("pos", QPoint(200, 200)).toPoint()); settings.endGroup(); } MainWindow::MainWindow() { ... readSettings(); } void MainWindow::closeEvent(QCloseEvent *event) { if (userReallyWantsToQuit()) { writeSettings(); event->accept(); } else { event->ignore(); } }
------解决方案--------------------
1.把表中内容存储到一个文件里面,然后在程序启动时,再读出来……
2.或者直接用QSettings