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
8
10{
11//! [0]
12 QSettings settings("MySoft", "Star Runner");
13//! [0]
14}
15
17{
18//! [1]
19 QCoreApplication::setOrganizationName("MySoft");
20//! [1] //! [2]
21 QCoreApplication::setOrganizationDomain("mysoft.com");
22//! [2] //! [3]
23 QCoreApplication::setApplicationName("Star Runner");
24//! [3]
25
26//! [4]
27 QSettings settings;
28//! [4]
29
30//! [5]
31 settings.setValue("editor/wrapMargin", 68);
32//! [5] //! [6]
33 int margin = settings.value("editor/wrapMargin").toInt();
34//! [6]
35 {
36//! [7]
37 int margin = settings.value("editor/wrapMargin", 80).toInt();
38//! [7]
39 }
40
41//! [8]
42 settings.setValue("mainwindow/size", win->size());
43//! [8] //! [9]
44 settings.setValue("mainwindow/fullScreen", win->isFullScreen());
45//! [9] //! [10]
46 settings.setValue("outputpanel/visible", panel->isVisible());
47//! [10]
48
49//! [11]
50 settings.beginGroup("mainwindow");
51 settings.setValue("size", win->size());
52 settings.setValue("fullScreen", win->isFullScreen());
53 settings.endGroup();
54//! [11]
55
56//! [12]
57 settings.beginGroup("outputpanel");
58 settings.setValue("visible", panel->isVisible());
59 settings.endGroup();
60//! [12]
61}
62
64{
65//! [13]
66 QSettings obj1("MySoft", "Star Runner");
67//! [13] //! [14]
68 QSettings obj2("MySoft");
69 QSettings obj3(QSettings::SystemScope, "MySoft", "Star Runner");
70 QSettings obj4(QSettings::SystemScope, "MySoft");
71//! [14]
72
73 {
74//! [15]
75 QSettings settings(QSettings::IniFormat, QSettings::UserScope,
76 "MySoft", "Star Runner");
77//! [15]
78 }
79
80 {
81 QSettings settings("starrunner.ini", QSettings::IniFormat);
82 }
83
84 {
85 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft",
86 QSettings::NativeFormat);
87 }
88}
89
90class MainWindow : public QMainWindow
91{
92public:
94
97
98protected:
99 void closeEvent(QCloseEvent *event) override;
100};
101
102//! [16]
104{
105 QSettings settings("Moose Soft", "Clipper");
106
107 settings.beginGroup("MainWindow");
108 settings.setValue("geometry", saveGeometry());
109 settings.endGroup();
110}
111//! [16]
112
113//! [17]
115{
116 QSettings settings("Moose Soft", "Clipper");
117
118 settings.beginGroup("MainWindow");
119 const auto geometry = settings.value("geometry", QByteArray()).toByteArray();
120 if (geometry.isEmpty())
121 setGeometry(200, 200, 400, 400);
122 else
123 restoreGeometry(geometry)
124 settings.endGroup();
125}
126//! [17]
127
128//! [18]
130{
131//! [18] //! [19]
133//! [19] //! [20]
134}
135//! [20]
136
137bool userReallyWantsToQuit() { return true; }
138
139//! [21]
140void MainWindow::closeEvent(QCloseEvent *event)
141{
144 event->accept();
145 } else {
146 event->ignore();
147 }
148}
149//! [21]
void closeEvent(QCloseEvent *event) override
[21]
void readSettings()
[16]
void writeSettings()
[16]
QWidget * win
Definition settings.cpp:6
QWidget * panel
Definition settings.cpp:7
void snippet_locations()
Definition settings.cpp:63
void snippet_ctor2()
Definition settings.cpp:16
void snippet_ctor1()
Definition settings.cpp:9
bool userReallyWantsToQuit()
[20]
Definition settings.cpp:137