Skip to content

Commit 00886c0

Browse files
committed
implement Upcast<QGuiApplication> for QApplication
1 parent 79eec17 commit 00886c0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

crates/cxx-qt-lib-extras/src/gui/qapplication.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
use core::pin::Pin;
7-
use cxx_qt_lib::{QByteArray, QFont, QString, QStringList, QVector};
7+
use cxx_qt::Upcast;
8+
use cxx_qt_lib::{QByteArray, QFont, QGuiApplication, QString, QStringList, QVector};
9+
use std::ops::Deref;
810

911
#[cxx::bridge]
1012
mod ffi {
@@ -18,12 +20,28 @@ mod ffi {
1820
include!("cxx-qt-lib/qvector.h");
1921
type QVector_QByteArray = cxx_qt_lib::QVector<QByteArray>;
2022
include!("cxx-qt-lib/qfont.h");
23+
2124
type QFont = cxx_qt_lib::QFont;
25+
include!("cxx-qt-lib/qguiapplication.h");
26+
type QGuiApplication = cxx_qt_lib::QGuiApplication;
2227

2328
include!("cxx-qt-lib-extras/qapplication.h");
2429
type QApplication;
2530
}
2631

32+
#[namespace = "rust::cxxqt1"]
33+
unsafe extern "C++" {
34+
include!("cxx-qt/casting.h");
35+
36+
#[doc(hidden)]
37+
#[rust_name = "upcast_qapplication"]
38+
unsafe fn upcastPtr(thiz: *const QApplication) -> *const QGuiApplication;
39+
40+
#[doc(hidden)]
41+
#[rust_name = "downcast_qapplication"]
42+
unsafe fn downcastPtr(base: *const QGuiApplication) -> *const QApplication;
43+
}
44+
2745
#[namespace = "rust::cxxqtlib1"]
2846
unsafe extern "C++" {
2947
#[doc(hidden)]
@@ -93,6 +111,24 @@ mod ffi {
93111

94112
pub use ffi::QApplication;
95113

114+
impl Upcast<QGuiApplication> for QApplication {
115+
unsafe fn upcast_ptr(this: *const Self) -> *const QGuiApplication {
116+
ffi::upcast_qapplication(this)
117+
}
118+
119+
unsafe fn from_base_ptr(base: *const QGuiApplication) -> *const Self {
120+
ffi::downcast_qapplication(base)
121+
}
122+
}
123+
124+
impl Deref for QApplication {
125+
type Target = QGuiApplication;
126+
127+
fn deref(&self) -> &Self::Target {
128+
self.upcast()
129+
}
130+
}
131+
96132
impl QApplication {
97133
/// Prepends path to the beginning of the library path list,
98134
/// ensuring that it is searched for libraries first.

0 commit comments

Comments
 (0)