Git Product home page Git Product logo

Comments (2)

Riateche avatar Riateche commented on August 16, 2024 1

What is the implementation of StaticUpcast<QObject> for this type? Slots created by #[slot] attribute will use the object returned from that implementation as the parent object, so if that object is deleted, the connection to your slot will be deregistered. You should make sure that the object returned by StaticUpcast<QObject> lives long enough.

Another possibility is that your self object got deleted. Slots created by #[slot] attribute retain a weak reference to self, so they won't prevent it from being deleted. Make sure you have strong references to self. You can write a Drop implementation for your type to check if it was deleted.

Please don't post code as images. Code in images cannot be copied and is hard to read.

from examples.

DreamSaddle avatar DreamSaddle commented on August 16, 2024

@Riateche
Thank you!
I solved!extended the QObject live time.
But must declared a variable in QApplication::init method. Otherwise it won't work.

Such as

#[derive(Debug)]
struct MainWindow {
    transText: Rc<TransText>,
    optLine: Rc<OptLine>,
}

pub fn startQt() {
    QApplication::init(|_| unsafe {
        let mainWindow = QMainWindow::new_0a();
        let windowWidget = QWidget::new_1a(&mainWindow);

        // I declared a variable in here, but not used
        let _mw = initWindowWidgets(&windowWidget);

        mainWindow.set_fixed_size_2a(700, 200);
        windowWidget.resize_1a(&mainWindow.size());
        mainWindow.set_window_title(&qs("Youdao Dict"));
        mainWindow.show();
        QApplication::exec()
    })
}


unsafe fn initWindowWidgets(windowWidget: &QBox<QWidget>) -> Rc<MainWindow> {
    let vBox = QVBoxLayout::new_1a(windowWidget);
    vBox.set_contents_margins_4a(0, 0, 0, 0);
    vBox.set_spacing(2);
    vBox.set_direction(Direction::Down);
    

    //初始化输入框
    let transText = TransText::new(&vBox);
    
    //初始化操作栏
    let _optLine = OptLine::new(&vBox, &transText);

    let mw = Rc::new(MainWindow{
        transText: transText,
        optLine: _optLine
    });
    mw
}

from examples.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.