Qt
6.x
The Qt SDK
Loading...
Searching...
No Matches
qtcast.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 <QLabel>
5
#include <QPushButton>
6
7
#include "qtcast.h"
8
9
MyWidget::MyWidget
()
10
{
12
QObject
*
obj
=
new
MyWidget
;
14
16
QWidget
*
widget
=
qobject_cast<QWidget *>
(
obj
);
18
20
MyWidget
*myWidget = qobject_cast<MyWidget *>(
obj
);
22
24
QLabel
*
label
= qobject_cast<QLabel *>(
obj
);
26
// label is 0
28
30
if
(
QLabel
*
label
= qobject_cast<QLabel *>(
obj
)) {
32
label
->setText(
tr
(
"Ping"
));
33
}
else
if
(
QPushButton
*
button
= qobject_cast<QPushButton *>(
obj
)) {
34
button
->
setText
(
tr
(
"Pong!"
));
35
}
37
}
38
39
int
main
()
40
{
41
return
0;
42
}
MyWidget
[23]
Definition
src_corelib_kernel_qobject.cpp:226
MyWidget::MyWidget
MyWidget()
Definition
src_corelib_kernel_qobject.cpp:239
QAbstractButton::setText
void setText(const QString &text)
Definition
qabstractbutton.cpp:480
QLabel
The QLabel widget provides a text or image display.
Definition
qlabel.h:20
QObject
\inmodule QtCore
Definition
qobject.h:90
QPushButton
The QPushButton widget provides a command button.
Definition
qpushbutton.h:20
QWidget
The QWidget class is the base class of all user interface objects.
Definition
qwidget.h:99
widget
QOpenGLWidget * widget
[1]
Definition
doc_gui_widgets_qopenglwidget.cpp:53
button
QPushButton * button
[2]
Definition
doc_src_properties.cpp:35
label
GLuint GLsizei const GLchar * label
[43]
Definition
qopengles2ext.h:156
obj
GLhandleARB obj
[2]
Definition
qopenglext.h:4164
main
int main()
Definition
qtcast.cpp:39
tr
#define tr(X)
Definition
qtemporaryfile.cpp:21
qobject_cast< QWidget * >
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition
qwidget.h:786
qtbase
src
corelib
doc
snippets
qtcast
qtcast.cpp
Generated by
1.9.7