Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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{
12 QSettings settings("MySoft", "Star Runner");
14}
15
17{
25
29
31 settings.setValue("editor/wrapMargin", 68);
33 int margin = settings.value("editor/wrapMargin").toInt();
35 {
37 int margin = settings.value("editor/wrapMargin", 80).toInt();
39 }
40
42 settings.setValue("mainwindow/size", win->size());
44 settings.setValue("mainwindow/fullScreen", win->isFullScreen());
46 settings.setValue("outputpanel/visible", panel->isVisible());
48
50 settings.beginGroup("mainwindow");
51 settings.setValue("size", win->size());
52 settings.setValue("fullScreen", win->isFullScreen());
55
57 settings.beginGroup("outputpanel");
58 settings.setValue("visible", panel->isVisible());
61}
62
64{
66 QSettings obj1("MySoft", "Star Runner");
68 QSettings obj2("MySoft");
69 QSettings obj3(QSettings::SystemScope, "MySoft", "Star Runner");
70 QSettings obj4(QSettings::SystemScope, "MySoft");
72
73 {
76 "MySoft", "Star Runner");
78 }
79
80 {
81 QSettings settings("starrunner.ini", QSettings::IniFormat);
82 }
83
84 {
85 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft",
87 }
88}
89
90class MainWindow : public QMainWindow
91{
92public:
94
95 void writeSettings();
96 void readSettings();
97
98protected:
99 void closeEvent(QCloseEvent *event) override;
100};
101
104{
105 QSettings settings("Moose Soft", "Clipper");
106
107 settings.beginGroup("MainWindow");
108 settings.setValue("geometry", saveGeometry());
110}
112
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
125}
127
130{
132 readSettings();
134}
136
137bool userReallyWantsToQuit() { return true; }
138
141{
142 if (userReallyWantsToQuit()) {
144 event->accept();
145 } else {
146 event->ignore();
147 }
148}
void closeEvent(QCloseEvent *event) override
[21]
void readSettings()
[16]
void writeSettings()
[16]
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
static void setOrganizationDomain(const QString &orgDomain)
static void setOrganizationName(const QString &orgName)
[11]
static void setApplicationName(const QString &application)
The QMainWindow class provides a main application window.
Definition qmainwindow.h:25
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
\inmodule QtCore
Definition qsettings.h:30
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
@ NativeFormat
Definition qsettings.h:49
@ SystemScope
Definition qsettings.h:86
void setValue(QAnyStringView key, const QVariant &value)
Sets the value of setting key to value.
QVariant value(QAnyStringView key, const QVariant &defaultValue) const
Returns the value for setting key.
void beginGroup(QAnyStringView prefix)
Appends prefix to the current group.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:886
bool isFullScreen() const
Definition qwidget.cpp:2982
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QByteArray saveGeometry() const
Definition qwidget.cpp:7337
bool restoreGeometry(const QByteArray &geometry)
Definition qwidget.cpp:7449
bool isVisible() const
Definition qwidget.h:874
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
struct _cl_event * event
QWidget * win
Definition settings.cpp:6
void snippet_locations()
Definition settings.cpp:63
void snippet_ctor2()
Definition settings.cpp:16
QWidget * panel
Definition settings.cpp:7
void snippet_ctor1()
Definition settings.cpp:9
bool userReallyWantsToQuit()
[20]
Definition settings.cpp:137
QSettings settings("MySoft", "Star Runner")
[0]