Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- MainWindow(QWidget *parent = 0);
- ~MainWindow();
- private:
- QWidget *pMainWidget;
- QHBoxLayout *pMainLayout;
- QSettings *pSetting;
- QLabel *pLabel;
- QPushButton *pButtonShow;
- QPushButton *pButtonSet;
- QLineEdit *pLineEdit;
- QString pSettingFile;
- public slots:
- void showSettingData();
- void setData();
- };
- #include "mainwindow.h"
- #include <QtCore/QCoreApplication>
- #include <QApplication>
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- {
- pMainWidget = new QWidget (parent);
- pMainLayout = new QHBoxLayout(pMainWidget);
- pLabel = new QLabel("Output comes here",pMainWidget);
- pLineEdit = new QLineEdit();
- pButtonShow = new QPushButton("Show", pMainWidget);
- pButtonSet = new QPushButton("Set", pMainWidget);
- setCentralWidget(pMainWidget);
- pMainWidget->setLayout(pMainLayout);
- pMainLayout->addWidget(pLabel);
- pMainLayout->addWidget(pButtonShow);
- pMainLayout->addWidget(pLineEdit);
- pMainLayout->addWidget(pButtonSet);
- pSettingFile = QApplication::applicationDirPath()+"settings.ini";
- QObject::connect(pButtonShow, SIGNAL(clicked()), this, SLOT(showSettingData()));
- QObject::connect(pButtonSet, SIGNAL(clicked()), this, SLOT(setData()));
- }
- MainWindow::~MainWindow()
- {
- }
- void MainWindow::setData()
- {
- QSettings Setting(pSettingFile, QSettings::NativeFormat);
- QString data = pLineEdit->text();
- Setting.setValue("baseurl", data);
- }
- void MainWindow::showSettingData()
- {
- QSettings Setting(pSettingFile, QSettings::NativeFormat);
- if (Setting.contains("baseurl"))
- {
- QString data = Setting.value("baseurl").toString();
- pLabel->setText(data);
- }
- }
- #include "mainwindow.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
- Setting.setValue("baseurl", data);
- Setting.sync();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement