Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rust + Qt:The trait cpp_core::cpp_box::CppDeletable is not implemented for LoginPage #16

Open
chatzich opened this issue May 5, 2021 · 0 comments

Comments

@chatzich
Copy link

chatzich commented May 5, 2021

I am new to Rust and I have the above code with which I am trying to create a QWizardPage and add it to a QWizard, I have inserted the proper widget to the page but when I am trying to add the page as component into the wizard I am taking this strange error

cpp_core::cpp_box::CppDeletable is not implemented for LoginPage

    use cpp_core::{Ptr, StaticUpcast};
    use qt_core::{qs, slot, QBox, QObject, SlotNoArgs};
    use qt_widgets::{
        QWizard, QApplication, QHBoxLayout, QWizardPage, QVBoxLayout, QLineEdit, QLabel
    };
    use qt_widgets::q_line_edit::{
        EchoMode
    };
    use std::rc::Rc;
    
    
    struct LoginPage {
        page: QBox<QWizardPage>,
        usernamelb: QBox<QLabel>,
        username: QBox<QLineEdit>,
        passwordlb: QBox<QLabel>,
        password: QBox<QLineEdit>
    }
    
    impl StaticUpcast<QObject> for LoginPage {
        unsafe fn static_upcast(ptr: Ptr<Self>) -> Ptr<QObject> {
            ptr.page.as_ptr().static_upcast()
        }
    }
    
    impl LoginPage {
        fn new() -> Rc<LoginPage> {
            unsafe {
                let page = QWizardPage::new_0a();
                let vmainlayout = QVBoxLayout::new_1a(&page);
                let usernamelayout = QHBoxLayout::new_1a(&page);
                let passwordlayout = QHBoxLayout::new_1a(&page);
                vmainlayout.add_layout_1a(&usernamelayout);
                vmainlayout.add_layout_1a(&passwordlayout);
                let usernamelb = QLabel::new();
                usernamelb.set_text(&qs("Username:"));
                usernamelayout.add_widget(&usernamelb);
    
                let username = QLineEdit::new();
                usernamelayout.add_widget(&username);
    
                let passwordlb = QLabel::new();
                passwordlb.set_text(&qs("Password:"));
                
                passwordlayout.add_widget(&passwordlb);
    
                let password = QLineEdit::new();
                password.set_echo_mode(EchoMode::Password);
                passwordlayout.add_widget(&password);
                let this = Rc::new(LoginPage {
                    page,
                    usernamelb,
                    username,
                    passwordlb,
                    password
                });
                this
            }
        }
    }
    
    struct Wizard {
        wizard: QBox<QWizard>,
        loginPage: QBox<LoginPage>
    }
    
    impl StaticUpcast<QObject> for Wizard {
        unsafe fn static_upcast(ptr: Ptr<Self>) -> Ptr<QObject> {
            ptr.wizard.as_ptr().static_upcast()
        }
    }
    
    impl Wizard {
        fn new() -> Rc<Wizard> {
            unsafe {
                let wizard = QWizard::new_0a();
                let loginPage = LoginPage::new();
                let this = Rc::new(Wizard {
                    wizard,
                    loginPage
                });
                this.init();
                this
            }
        }
    
        unsafe fn init(self: &Rc<Self>) {
            self.wizard.rejected().connect(&self.slot_on_wizard_rejected());
        }
    }
    
    fn main() {
        QApplication::init(|_| unsafe {
            let _wizard = Wizard::new();
            _wizard.wizard.show();
    
            QApplication::exec()
        })
    }


# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant