Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. class MainWindow : public QMainWindow
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. MainWindow(QWidget *parent = 0);
  7. ~MainWindow();
  8.  
  9. private:
  10. QWidget *pMainWidget;
  11. QHBoxLayout *pMainLayout;
  12. QSettings *pSetting;
  13.  
  14. QLabel *pLabel;
  15. QPushButton *pButtonShow;
  16. QPushButton *pButtonSet;
  17. QLineEdit *pLineEdit;
  18.  
  19. QString pSettingFile;
  20.  
  21. public slots:
  22. void showSettingData();
  23. void setData();
  24. };
  25.  
  26. #include "mainwindow.h"
  27. #include <QtCore/QCoreApplication>
  28. #include <QApplication>
  29.  
  30. MainWindow::MainWindow(QWidget *parent)
  31. : QMainWindow(parent)
  32. {
  33.  
  34. pMainWidget = new QWidget (parent);
  35. pMainLayout = new QHBoxLayout(pMainWidget);
  36.  
  37. pLabel = new QLabel("Output comes here",pMainWidget);
  38. pLineEdit = new QLineEdit();
  39. pButtonShow = new QPushButton("Show", pMainWidget);
  40. pButtonSet = new QPushButton("Set", pMainWidget);
  41.  
  42. setCentralWidget(pMainWidget);
  43. pMainWidget->setLayout(pMainLayout);
  44. pMainLayout->addWidget(pLabel);
  45. pMainLayout->addWidget(pButtonShow);
  46. pMainLayout->addWidget(pLineEdit);
  47. pMainLayout->addWidget(pButtonSet);
  48.  
  49. pSettingFile = QApplication::applicationDirPath()+"settings.ini";
  50.  
  51. QObject::connect(pButtonShow, SIGNAL(clicked()), this, SLOT(showSettingData()));
  52. QObject::connect(pButtonSet, SIGNAL(clicked()), this, SLOT(setData()));
  53.  
  54. }
  55.  
  56. MainWindow::~MainWindow()
  57. {
  58.  
  59. }
  60.  
  61. void MainWindow::setData()
  62. {
  63. QSettings Setting(pSettingFile, QSettings::NativeFormat);
  64.  
  65. QString data = pLineEdit->text();
  66. Setting.setValue("baseurl", data);
  67. }
  68.  
  69. void MainWindow::showSettingData()
  70. {
  71. QSettings Setting(pSettingFile, QSettings::NativeFormat);
  72.  
  73. if (Setting.contains("baseurl"))
  74. {
  75. QString data = Setting.value("baseurl").toString();
  76. pLabel->setText(data);
  77. }
  78.  
  79. }
  80.  
  81. #include "mainwindow.h"
  82. #include <QApplication>
  83.  
  84. int main(int argc, char *argv[])
  85. {
  86. QApplication a(argc, argv);
  87. MainWindow w;
  88. w.show();
  89.  
  90. return a.exec();
  91. }
  92.  
  93. Setting.setValue("baseurl", data);
  94. Setting.sync();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement