Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
settings.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtGui>
5
7{
8//! [0]
9 QSettings settings("MySoft", "Star Runner");
10//! [0]
11}
12
14{
15//! [1]
16 QCoreApplication::setOrganizationName("MySoft");
17//! [1] //! [2]
18 QCoreApplication::setOrganizationDomain("mysoft.com");
19//! [2] //! [3]
20 QCoreApplication::setApplicationName("Star Runner");
21//! [3]
22
23//! [4]
24 QSettings settings;
25//! [4]
26
27//! [5]
28 settings.setValue("editor/wrapMargin", 68);
29//! [5] //! [6]
30 int margin = settings.value("editor/wrapMargin").toInt();
31//! [6]
32 {
33//! [7]
34 int margin = settings.value("editor/wrapMargin", 80).toInt();
35//! [7]
36 }
37}
38
39#if __has_include(<QWidget>)
40#include <QWidget>
41
42void snippet_ctor_widgets()
43{
44 QWidget *win;
45 QWidget *panel;
46 QSettings settings;
47
48//! [8]
49 settings.setValue("mainwindow/size", win->size());
50//! [8] //! [9]
51 settings.setValue("mainwindow/fullScreen", win->isFullScreen());
52//! [9] //! [10]
53 settings.setValue("outputpanel/visible", panel->isVisible());
54//! [10]
55
56//! [11]
57 settings.beginGroup("mainwindow");
58 settings.setValue("size", win->size());
59 settings.setValue("fullScreen", win->isFullScreen());
60 settings.endGroup();
61//! [11]
62
63//! [12]
64 settings.beginGroup("outputpanel");
65 settings.setValue("visible", panel->isVisible());
66 settings.endGroup();
67//! [12]
68}
69#endif
70
72{
73//! [13]
74 QSettings obj1("MySoft", "Star Runner");
75//! [13] //! [14]
76 QSettings obj2("MySoft");
77 QSettings obj3(QSettings::SystemScope, "MySoft", "Star Runner");
78 QSettings obj4(QSettings::SystemScope, "MySoft");
79//! [14]
80
81 {
82//! [15]
83 QSettings settings(QSettings::IniFormat, QSettings::UserScope,
84 "MySoft", "Star Runner");
85//! [15]
86 }
87
88 {
89 QSettings settings("starrunner.ini", QSettings::IniFormat);
90 }
91
92 {
93 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft",
94 QSettings::NativeFormat);
95 }
96}
97
98#if __has_include(<QWidget>)
99#include <QMainWindow>
100
101class MainWindow : public QMainWindow
102{
103public:
104 MainWindow();
105
106 void writeSettings();
107 void readSettings();
108
109protected:
110 void closeEvent(QCloseEvent *event) override;
111};
112
113//! [16]
114void MainWindow::writeSettings()
115{
116 QSettings settings("Moose Soft", "Clipper");
117
118 settings.beginGroup("MainWindow");
119 settings.setValue("geometry", saveGeometry());
120 settings.endGroup();
121}
122//! [16]
123
124//! [17]
125void MainWindow::readSettings()
126{
127 QSettings settings("Moose Soft", "Clipper");
128
129 settings.beginGroup("MainWindow");
130 const auto geometry = settings.value("geometry", QByteArray()).toByteArray();
131 if (geometry.isEmpty())
132 setGeometry(200, 200, 400, 400);
133 else
134 restoreGeometry(geometry);
135 settings.endGroup();
136}
137//! [17]
138
139//! [18]
140MainWindow::MainWindow()
141{
142//! [18] //! [19]
143 readSettings();
144//! [19] //! [20]
145}
146//! [20]
147
148bool userReallyWantsToQuit() { return true; }
149
150//! [21]
151void MainWindow::closeEvent(QCloseEvent *event)
152{
153 if (userReallyWantsToQuit()) {
154 writeSettings();
155 event->accept();
156 } else {
157 event->ignore();
158 }
159}
160//! [21]
161#endif
#define __has_include(x)
void snippet_locations()
Definition settings.cpp:71
void snippet_ctor2()
Definition settings.cpp:13
void snippet_ctor1()
Definition settings.cpp:6