Widgets cargo template with UI support
ClosedPublic

Authored by psbarra on Sep 19 2019, 2:32 AM.

Details

Summary

This template introduces support for compile-time Qt Designer UI files.

Test Plan

execute "cargo run" from the templates/qt_widgets_cargo directory.

Diff Detail

Repository
R881 Rust Qt Binding Generator
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
psbarra requested review of this revision.Sep 19 2019, 2:32 AM
psbarra created this revision.

Noted a couple tweaks to the ui file support.

src/build.rs
487

Since an application can specify multiple ui files across arbitrary source directories, generating the output in the same directory will cause issues if the ui files have the same name.

494

Since the generated ui header will be included within other c++ files in the application I don't believe it should be added to the list of headers. That causes it to get run through moc which is likely not necessary since the including file will be run through moc.

psbarra updated this revision to Diff 66639.Sep 23 2019, 3:30 AM

Allow ui files with the same name from different directories.
Don't run generated headers through moc.

psbarra marked 2 inline comments as done.Sep 23 2019, 3:31 AM
vandenoever added a comment.EditedSep 27 2019, 9:09 PM

This patch works fine. Support for .ui files is a great addition.

I see an opportunity to make it a bit more interesting. You use ui.mesg->setText(simple.message()); to set a UI value once. This template only uses one method of the Rust code.

If you add QLineEdit and connect some signals and slots this code help somebody that starts from this template more, since signals and slots are nearly always required.

templates/qt_widgets_cargo/src/implementation.rs
13

You probably want this to be message: String::from("Hello World!").
Or you could keep message: String::new() and set the initial value in the UI layer.

20

This should be self.message.as_str() of &self.message.

psbarra updated this revision to Diff 66981.Sep 28 2019, 5:20 AM

Changed widgets and added more interaction between widgets (as suggested).

One challenge I'm noticing and don't have a good solution for is that there's no good way to specify the main.cpp's dependence on ui_main.h. The header is updated when building after modifying the ui file, however, the buld.rs script doesn't know that it then needs to recompile main.cpp since it's included there.

The workaround is to touch the dependent file (main.cpp in this case).

I looked but couldn't find a mechanism that would allow for passing the message content in the message_changed signal. It would be nice if Simple::messageChanged could be connected directly to QStatusBar::showMessage instead of having to write the lambda (minor nit).

psbarra marked 2 inline comments as done.Sep 28 2019, 5:22 AM

I like the new version.

One challenge I'm noticing and don't have a good solution for is that there's no good way to specify the main.cpp's dependence on ui_main.h. The header is updated when building after modifying the ui file, however, the buld.rs script doesn't know that it then needs to recompile main.cpp since it's included there.

The workaround is to touch the dependent file (main.cpp in this case).

Another solution is to add ui_main.h to compile_inputs.

I looked but couldn't find a mechanism that would allow for passing the message content in the message_changed signal. It would be nice if Simple::messageChanged could be connected directly to QStatusBar::showMessage instead of having to write the lambda (minor nit).

Right, it's an option to change that. A consideration is that always passing the new value has some performance overhead for converting the rust value to a Qt value.

psbarra updated this revision to Diff 67004.Sep 28 2019, 7:01 PM

add generated ui header file paths to the list of compile inputs. This triggers the library to be rebuilt when the ui file has been modified. Thanks for the suggestion.

This patch looks good now. I can land it for you.
To do so, I need you full name and email to amend the author information. Shall I use the name and mail from the mail that you sent me?

Sounds good. Thanks!

Paul Sbarra
sbarra.paul@gmail.com

vandenoever accepted this revision.Sep 29 2019, 3:38 PM
This revision is now accepted and ready to land.Sep 29 2019, 3:38 PM

Thank you very much. The patch has landed.

This revision was automatically updated to reflect the committed changes.