Rust-qt project compiling issue


i am trying to play with the "todo_list" example ( everything is working fine...but, if i try to add a "QFileDialog" or a "QMessageBox" to one of the slots, for instance :

    unsafe fn on_add_clicked(self: &Rc<Self>) {
        let filenames = QFileDialog::new();
        filenames.get_open_file_names_4a(None, &qs("Open files"), &qs("./"), &qs("Text files (*.s2p)"));

then i get errors:

error[E0599]: no method named `get_open_file_names_4a` found for struct `QBox<QFileDialog>` in the current scope

63 |         filenames.get_open_file_names_4a(None, &qs("Open files"), &qs("./"), &qs("Python/Text files (*.s2p)"));

   |         ----------^^^^^^^^^^^^^^^^^^^^^^

   |         |         |

   |         |         this is an associated function, not a method

   |         help: use associated function syntax instead: `QFileDialog::get_open_file_names_4a`

The "basic_form" examples uses a "QMessageBox" and everything works fine, so i assume that my problem is that i load the "Form" (QtDesigner ui file) with the ui_tools.

What i am doing wrong here?

I am trying to get it work since two days but until now i did not find the solution...

I thank you very much for your help in advance.

Best Regards.

Did you try following the compiler's suggestion? Replace filenames.get_open_file_names_4a with QFileDialog::get_open_file_names_4a.


yes i tried it but i get much stranger errors:

error[E0277]: the trait bound `Ptr<QWidget>: CastFrom<std::option::Option<_>>` is not satisfied

63    |         QFileDialog::get_open_file_names_4a(None, &qs("Open files"), &qs("./"), &qs("Python/Text files (*.s2p)"));

      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CastFrom<std::option::Option<_>>` is not implemented for `Ptr<QWidget>`


     ::: C:\Users\o00474597\.cargo\registry\src\\qt_widgets-0.5.0\src\


55362 |         parent: impl ::cpp_core::CastInto<::cpp_core::Ptr<crate::QWidget>>,

      |                      ----------------------------------------------------- required by this bound in `QFileDialog::get_open_file_names_4a`


      = help: the following implementations were found:

                <Ptr<T> as CastFrom<&'a CppBox<U>>>

                <Ptr<T> as CastFrom<&'a QBox<U>>>

                <Ptr<T> as CastFrom<&'a QPtr<U>>>

                <Ptr<T> as CastFrom<*const U>>

              and 5 others

      = note: required because of the requirements on the impl of `CastInto<Ptr<QWidget>>` for `std::option::Option<_>`


error: aborting due to previous error; 4 warnings emitted

Please read Forum Code Formatting and Syntax Highlighting and edit your prior post by using the pencil-shaped edit button under that post. Note that you can specify the language syntax to be used in highlighting by specifying the language at the end of the first row of three backticks. (Rust is the default language if you don't specify toml or c++ or something else.)

Many readers of this forum will ignore code snippets, compiler error reports, etc that do not follow the posting guidelines for new contributors that are pinned to the top of this forum. Even those who do respond may feel that the lack of following the forum posting guidelines is disrespectful of their time. Thanks. :clap:

Hi Tom,

I modified the format according to your recommendation.

Thank you!

Best Regards.

You should use NullPtr instead of None to specify null pointer as an argument. You can see all allowed argument types in the documentation of CastFrom. NullPtr is there, but Option<_> is not, so None cannot be used for an argument of type impl CastInto<_>.

1 Like

Thank you very much ! it's working :slight_smile:
I wish you a great weekend.
Best Regards.