What type to use for QWidget?

Hello

I want to make a struct which will act as a kind of global variable. This to be able to pass a QWidget object to functions.

I'm using Qt-rs..

Code:

#![windows_subsystem = "windows"]

use qt_widgets::{
    cpp_core::{CppBox, MutPtr},
    qt_core::QString,
    qt_core::Slot,
    QApplication, QLineEdit, QMessageBox, QPushButton, QVBoxLayout, QWidget,
    QLabel,
};

pub fn test(layout: QWidget) {
    println!("test");
}

struct Test {
    widget: QWidget,
}
impl Test {
    pub fn test(&self) {
        println!("Test");
    }
}

fn main() {

    /*
    let t = Test {
        widget: QWidget::new_0a(),
    };
    */

    QApplication::init(|_| unsafe {
        //let mut widget = t.widget;
        
        let mut widget = QWidget::new_0a();
        let mut layout = QVBoxLayout::new_1a(&mut widget).into_ptr();

        test(widget);
        
        layout.add_widget(&mut btn_add);

        widget.show();
        QApplication::exec()
    })
}

Error:

expected struct `qt_widgets::QWidget`, found struct `cpp_core::cpp_box::CppBox`

But when I change pub fn test(layout: QWidget) to pub fn test(layout: cpp_core::cpp_box::CppBox)

I get this error:

use of undeclared type or module `cpp_core`

How can I solve this? What type do I need to use?
Thanks!

To access the path cpp_core::cpp_box::CppBox directly, you would have to add the crate to Cargo.toml.

Alternatively you can use the reexport in qt_widgets, but then the path is qt_widgets::cpp_core::cpp_box::CppBox

When I try the path qt_widgets::cpp_core... I get the following error:

module `cpp_box` is private

Same when I import the cpp_core crate in my Cargo.toml.

Right, CppBox is directly in cpp_core.

Yes, and how do I solve the error that cpp_box is private?
Can I import that crate public somehow?

Use the public path qt_widgets::cpp_core::CppBox

2 Likes

Ait! It's working! Thanks mate.
Had to remove the extra cpp_box from the path.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.