Skip to content

Commit 311ddd9

Browse files
committed
cxx-qt-lib: implement Upcast<QGuiApplication> for QApplication
1 parent 8e829ef commit 311ddd9

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 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 {
@@ -19,11 +21,26 @@ mod ffi {
1921
type QVector_QByteArray = cxx_qt_lib::QVector<QByteArray>;
2022
include!("cxx-qt-lib/qfont.h");
2123
type QFont = cxx_qt_lib::QFont;
24+
include!("cxx-qt-lib/qguiapplication.h");
25+
type QGuiApplication = cxx_qt_lib::QGuiApplication;
2226

2327
include!("cxx-qt-lib-extras/qapplication.h");
2428
type QApplication;
2529
}
2630

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

94111
pub use ffi::QApplication;
95112

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

0 commit comments

Comments
 (0)