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
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
10{
12 QObject *obj = new MyWidget;
14
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
39int main()
40{
41 return 0;
42}
void setText(const QString &text)
The QLabel widget provides a text or image display.
Definition qlabel.h:20
\inmodule QtCore
Definition qobject.h:103
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
QPushButton * button
[2]
GLuint GLsizei const GLchar * label
[43]
GLhandleARB obj
[2]
int main()
Definition qtcast.cpp:39
#define tr(X)
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786