Hello
I tried to bind a button to a slot following this example.
I'm getting one error I don't understand.
Code:
#![windows_subsystem = "windows"]
//Importing the required stuff
use cpp_core::{Ptr, Ref, StaticUpcast};
use qt_core::{qs, slot, ContextMenuPolicy, QBox, QObject, QPoint, SlotNoArgs, QString};
use qt_widgets::{
QAction, QApplication, QLineEdit, QMenu, QMessageBox, QPushButton, QLabel, QTableWidget,
QTableWidgetItem, QVBoxLayout, QWidget, SlotOfQPoint, SlotOfQTableWidgetItemQTableWidgetItem,
};
use std::rc::Rc;
//Struct for Main window
struct MainWindow {
widget: QBox<QWidget>,
button: QBox<QPushButton>,
}
//From form-struct to base-struct ???
impl StaticUpcast<QObject> for MainWindow {
unsafe fn static_upcast(ptr: Ptr<Self>) -> Ptr<QObject> {
ptr.widget.as_ptr().static_upcast()
}
}
//Implementing functions for MainWindow
impl MainWindow {
//Defining all the graphical elements in MainWindow
//Returns the MainWindow in a Reference Counted Smart Pointer so it can have multiple owners
//and doesn't get destroyed until it has no owners anymore
fn new() -> Rc<MainWindow> {
unsafe {
//Widget
let widget = QWidget::new_0a();
let layout = QVBoxLayout::new_1a(&widget);
//Label
let label = QLabel::new();
label.set_text(&qs("Fucking cool label!"));
layout.add_widget(&label);
//Button
let button = QPushButton::from_q_string(&qs("Click me."));
layout.add_widget(&button);
let this = Rc::new(Self {
widget,
button,
});
this.init();
this
}
}
//Binding functions/slots to elements etc
unsafe fn init(self: &Rc<Self>) {
self.button
.clicked()
.connect(&self.test());
}
//Slots/Functions for buttons
#[slot(SlotNoArgs)]
unsafe fn test(self: &Rc<Self>) {
println!("{}", "Test 123...");
}
}
fn main() {
QApplication::init(|_| unsafe {
let _mw = MainWindow::new();
QApplication::exec()
})
}
Error
error[E0277]: the trait bound `&(): qt_core::connect::AsReceiver` is not satisfied
--> src/main.rs:58:22
|
58 | .connect(&self.test());
| ^^^^^^^^^^^^ the trait `qt_core::connect::AsReceiver` is not implemented for `&()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `qt_rs_3`.
I followed the example, so I don't see what I'm doing wrong.
Thanks.