Skip to content

Commit 21f2216

Browse files
committed
cxx-qt-lib: implement Upcast<QGuiApplication> for QApplication
1 parent 961ce60 commit 21f2216

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 {
@@ -24,6 +26,22 @@ mod ffi {
2426
type QApplication;
2527
}
2628

29+
#[namespace = "rust::cxxqt1"]
30+
unsafe extern "C++" {
31+
include!("cxx-qt/casting.h");
32+
33+
include!("cxx-qt-lib/qguiapplication.h");
34+
type QGuiApplication = cxx_qt_lib::QGuiApplication;
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 downcastPtrStatic(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)