Hello
I've updated my Rust to the latest version, and when I suddenly tried to run my code it outputs a lot of errors. I didn't changed my code though.
Code:
#![windows_subsystem = "windows"]
use qt_widgets::{
cpp_core::{CppBox, MutPtr},
qt_core::QString,
qt_core::Slot,
QApplication, QLineEdit, QMessageBox, QPushButton, QVBoxLayout, QWidget,
QLabel,
qt_gui::QFont,
qt_core::QObject,
QLayoutItem,
};
//Userinterface handling all the possible UserInterface-screens
//Each function is to build a specific userinterface (depending on e.g
//selected option)
struct UserInterface {
// layout: Option<CppBox<QVBoxLayout>>,
}
impl UserInterface {
//Constructor
pub fn new() -> UserInterface {
UserInterface {
// layout: None,
}
}
//Build the labels, buttons,... for the startscreen
pub fn build_start_screen(&mut self, window: cpp_core::MutPtr<QWidget>) {
unsafe {
//Big fat font
let mut big_font : CppBox<QFont> = QFont::new();
big_font.set_family(&QString::from_std_str("Sans Serif"));
big_font.set_point_size(24);
big_font.set_weight(400);
//Label 'Cat Manager'
let mut label_a : CppBox<QLabel> = QLabel::new();
label_a.set_text(&QString::from_std_str("Cat Manager"));
label_a.set_font(&big_font);
//Label 'Your favourite...'
let mut label_b : CppBox<QLabel> = QLabel::new();
label_b.set_text(&QString::from_std_str("Your favourite application to manage your best friends!"));
//Button to go to Option A-screen
let mut option_a_btn : CppBox<QPushButton> = QPushButton::new();
option_a_btn.set_text(&QString::from_std_str("Go option A"));
//When button option_a_btn is clicked we need to toggle the screen
//to the Option A-userinterface
//let window_ptr = window.as_mut_ptr();
let option_a_btn_clicked = Slot::new(move || {
println!("Rofl");
self.build_option_a_screen(window);
});
option_a_btn.clicked().connect(&option_a_btn_clicked);
//Add all the widgets to the layout
window.layout().add_widget(label_a.into_ptr());
window.layout().add_widget(label_b.into_ptr());
window.layout().add_widget(option_a_btn.into_ptr());
//self.layout = Some(layout);
}
}
//Build labels, options,... for the screen which shows when Option A gets selected
pub fn build_option_a_screen(&mut self, window: cpp_core::MutPtr<QWidget>) {
unsafe {
self.reset(window);
//Label 'Cat Manager'
let mut label_a : CppBox<QLabel> = QLabel::new();
label_a.set_text(&QString::from_std_str("Option A selected!"));
window.layout().add_widget(label_a.into_ptr());
}
}
pub fn reset(&mut self, window: cpp_core::MutPtr<QWidget>) {
unsafe {
while window.layout().count() > 0 {
let child : cpp_core::MutPtr<QLayoutItem> = window.layout().take_at(0);
window.layout().delete_later();
}
}
}
}
fn main() {
QApplication::init(|_app| unsafe {
let mut window : CppBox<QWidget> = QWidget::new_0a();
window.resize_2a(400, 250);
let mut layout : CppBox<QVBoxLayout> = QVBoxLayout::new_1a(&mut window);
let mut ui : UserInterface = UserInterface::new();
let window_ptr = window.as_mut_ptr();
ui.build_start_screen(window_ptr);
window.show();
QApplication::exec()
})
}
Errors:
Compiling Qt-rs v0.1.0 (/Users/niel/School/Rust/rust_gui/Qt-rs)
error[E0433]: failed to resolve: maybe a missing crate `qt_widgets`?
--> src/main.rs:3:5
|
3 | use qt_widgets::{
| ^^^^^^^^^^ maybe a missing crate `qt_widgets`?
error[E0432]: unresolved import `qt_widgets`
--> src/main.rs:3:5
|
3 | use qt_widgets::{
| ^^^^^^^^^^ maybe a missing crate `qt_widgets`?
error[E0433]: failed to resolve: use of undeclared type or module `QFont`
--> src/main.rs:32:48
|
32 | let mut big_font : CppBox<QFont> = QFont::new();
| ^^^^^ use of undeclared type or module `QFont`
error[E0433]: failed to resolve: use of undeclared type or module `QString`
--> src/main.rs:33:34
|
33 | big_font.set_family(&QString::from_std_str("Sans Serif"));
| ^^^^^^^ use of undeclared type or module `QString`
error[E0433]: failed to resolve: use of undeclared type or module `QString`
--> src/main.rs:39:31
|
39 | label_a.set_text(&QString::from_std_str("Cat Manager"));
| ^^^^^^^ use of undeclared type or module `QString`
error[E0433]: failed to resolve: use of undeclared type or module `QString`
--> src/main.rs:44:31
|
44 | label_b.set_text(&QString::from_std_str("Your favourite application to manage your best friends!"));
| ^^^^^^^ use of undeclared type or module `QString`
error[E0433]: failed to resolve: use of undeclared type or module `QString`
--> src/main.rs:48:36
|
48 | option_a_btn.set_text(&QString::from_std_str("Go option A"));
| ^^^^^^^ use of undeclared type or module `QString`
error[E0433]: failed to resolve: use of undeclared type or module `Slot`
--> src/main.rs:53:40
|
53 | let option_a_btn_clicked = Slot::new(move || {
| ^^^^ use of undeclared type or module `Slot`
error[E0433]: failed to resolve: use of undeclared type or module `QString`
--> src/main.rs:76:31
|
76 | label_a.set_text(&QString::from_std_str("Option A selected!"));
| ^^^^^^^ use of undeclared type or module `QString`
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:32:32
|
32 | let mut big_font : CppBox<QFont> = QFont::new();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `QFont` in this scope
--> src/main.rs:32:39
|
20 | impl UserInterface {
| - help: you might be missing a type parameter: `<QFont>`
...
32 | let mut big_font : CppBox<QFont> = QFont::new();
| ^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:38:31
|
38 | let mut label_a : CppBox<QLabel> = QLabel::new();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:43:31
|
43 | let mut label_b : CppBox<QLabel> = QLabel::new();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:47:36
|
47 | let mut option_a_btn : CppBox<QPushButton> = QPushButton::new();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:75:31
|
75 | let mut label_a : CppBox<QLabel> = QLabel::new();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:96:26
|
96 | let mut window : CppBox<QWidget> = QWidget::new_0a();
| ^^^^^^ not found in this scope
error[E0412]: cannot find type `CppBox` in this scope
--> src/main.rs:99:26
|
99 | let mut layout : CppBox<QVBoxLayout> = QVBoxLayout::new_1a(&mut window);
| ^^^^^^ not found in this scope
error: aborting due to 17 previous errors
Cargo.toml
[package]
name = "Qt-rs"
version = "0.1.0"
authors = ["ONiel"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
qt_core = "0.4.1"
qt_gui = "0.4.1"
qt_widgets = "0.4.1"
qt_ui_tools = "0.4.1"
qt_3d_core = "0.4.1"
qt_3d_render = "0.4.1"
qt_3d_input = "0.4.1"
qt_3d_logic = "0.4.1"
qt_3d_extras = "0.4.1"
qt_charts = "0.4.1"
cpp_core = "0.5.1"
It compiled and ran before the update.
Thanks!