News for hackers. Stuff that matters.
Re:Speedy Desktop Apps with GTK and Rust by dijit on Saturday July 06, 2019 @08:41AM (#20369360)
I tend to prefer Qt as an end user, are there similar tutorials for Qt+Rust?

I remember someone telling me that it’s not as good a fit but I can’t remember why that is.

Re:Speedy Desktop Apps with GTK and Rust by simion314 on Saturday July 06, 2019 @08:51AM (#20369405)
GTK is a C toolkit and Qt is C++, it is easier for other languages to use GTK if those languages have a way to interact with C library. There are a lot of bindings to GTK and very few to Qt.
Re:Speedy Desktop Apps with GTK and Rust by pknopf on Saturday July 06, 2019 @09:05AM (#20369457)
Re:Speedy Desktop Apps with GTK and Rust by simion314 on Saturday July 06, 2019 @09:40AM (#20369601)
There were C# Qt bindings since many years ago but those were not official supported so the quality was not that good,once there was a Java official binding/port that was dropped after a short time, I would not use someone's hobby bindings for a real world project(I mean a project with many users that you need to support for years , through OS and oteher system updates)
Re:Speedy Desktop Apps with GTK and Rust by pknopf on Saturday July 06, 2019 @10:20AM (#20369803)
I'm the author.

The QtSharp project used technology that couldn't really address the problem (MonoCppSharp).

QML.Net is different. It is purely a QML integration (no c++ wrapper), using a C interop.

There is extensive unit tests for QML.Net, including garbage collection tests.

I consider it segfault-proof.

It's currently used in production on embedded medical devices: https://medxchange.com/4klear-all-in-one-camera-recorder/

Re:Speedy Desktop Apps with GTK and Rust by simion314 on Saturday July 06, 2019 @10:55AM (#20369969)
Sounds like a nice project, I did not want to insinuate that the quality is not good, I did not used Qt in a few years(since Qt4 days) so I am not sure about QML, without doing any research I think I am inclined to use the classic QtWidgedts for a desktop applications, SQML seems to me more mobile or designer first toolkit.

I strongly believe that Microsoft made a huge mistake not making .Net WPF and Silverlight cross platform and open source it. they would have made money by selling the Visual Studio IDE,

Re:Speedy Desktop Apps with GTK and Rust by mlevental on Saturday July 06, 2019 @11:26AM (#20370117)
does it work with .net core? i.e. linux?
Re:Speedy Desktop Apps with GTK and Rust by pknopf on Saturday July 06, 2019 @12:10PM (#20370328)
It works on every platform Qt and .NET Core works.

I run it on embedded Linux.

Travis and Appveyor cover tests for Linux/Mac/Windows.

Re:Speedy Desktop Apps with GTK and Rust by mlevental on Saturday July 06, 2019 @12:35PM (#20370445)
that's pretty amazing. i've been looking for a gui framework that i can use with csharp on linux. i'll take a look.
Re:Speedy Desktop Apps with GTK and Rust by dijit on Saturday July 06, 2019 @10:11AM (#20369756)
That explains a lot. Thank you. :)
Re:Speedy Desktop Apps with GTK and Rust by arusahni on Saturday July 06, 2019 @09:07AM (#20369465)
I was wondering the same thing a few weeks back and found this project from the folks at KDE: https://github.com/KDE/rust-qt-binding-generator

They provide some tutorial links in the README.

Re:Speedy Desktop Apps with GTK and Rust by hdfbdtbcdg on Saturday July 06, 2019 @08:49AM (#20369397)
As a guess it is probably because GTK has a C API whilst Qt is C++.
Re:Speedy Desktop Apps with GTK and Rust by ogoffart on Saturday July 06, 2019 @10:46AM (#20369926)
Re:Speedy Desktop Apps with GTK and Rust by Zardoz84 on Saturday July 06, 2019 @08:52AM (#20369411)
the problem is that QT is write on C++. It makes harder to make bindings to any other language.
Re:Speedy Desktop Apps with GTK and Rust by gmueckl on Saturday July 06, 2019 @09:44AM (#20369625)
The real problem isn't that C++ is that hard to bind. Writing a C style wrapper around the OO style code in Qt is easy. But Qt relies on compile time code generation for event handling, properties and such, and this part is hard to replicate in other languages. It can be done; PyQt, PySide, etc do it, but it takes quite some effort.
Re:Speedy Desktop Apps with GTK and Rust by 0815test on Saturday July 06, 2019 @03:25PM (#20371374)
Rust has excellent support for compile-time codegen.
Re:Speedy Desktop Apps with GTK and Rust by gmueckl on Saturday July 06, 2019 @04:18PM (#20371671)
You are welcome to try to duplicate the functionality of the moc tool somehow. If it was trivial, it would have been done already.
Re:Speedy Desktop Apps with GTK and Rust by ogoffart on Saturday July 06, 2019 @06:07PM (#20372309)
It has been done already: https://github.com/woboq/qmetaobject-rs
Re:Speedy Desktop Apps with GTK and Rust by gmueckl on Saturday July 06, 2019 @08:09PM (#20372813)
Hm... unless I am mistaken, this misses the ability to write arbitrary slots and connect them. If I am right, then a major part of what moc is responsible for - the whole signal/slot glue code - is not covered in this library.
Re:Speedy Desktop Apps with GTK and Rust by kbumsik on Saturday July 06, 2019 @08:59AM (#20369433)
Does C++ make it harder to bind than C? I'm genuinely curious.
Re:Speedy Desktop Apps with GTK and Rust by flohofwoe on Saturday July 06, 2019 @09:21AM (#20369520)
Yes because C++ doesn't have a standardized ABI, and C++ language concepts sometimes map badly to other languages, while C is sort of a lowest-common-demoninator (pretty much any language can call C functions through some sort of FFI mechanism).

The usual workaround is to wrap the C++ API into a C API.

Re:Speedy Desktop Apps with GTK and Rust by cesarb on Saturday July 06, 2019 @02:14PM (#20370978)
> C++ doesn't have a standardized ABI

It does: the "Itanium ABI" (initially for IA64, adopted for other architectures).

Re:Speedy Desktop Apps with GTK and Rust by kbumsik on Saturday July 06, 2019 @09:46AM (#20369635)
That explains very well. I didn't know that C++ doesn't have a stable ABI. Is it because C++ is so complicated to make a standard ABI?
Re:Speedy Desktop Apps with GTK and Rust by jcranmer on Saturday July 06, 2019 @11:14AM (#20370067)
The other commenters so far have blamed name mangling. Name mangling isn't actually that big of a deal: to mangle most functions, just write out the fully-qualified name of the function/method, convert each component of the name individually via a simple function, and then tack on the mangling of the types for every argument. Name mangling can get hairy, but realistically, you're not going to be linking against a template using an unnamed lambda as a parameter.

The minor complication you get is that the C/C++ ecosystem uses char, short, int, long, and long long to determine types, while most other languages use a more sensible i8, i16, i32, i64 system. This means you can't use the native type system of your target language as the base for mangling, since i32 and i64 do not map cleanly to int, long, and long long. (Doesn't help either that pre-stdint.h libraries for defining target-independent i64 types may have chosen a different value for i64 than stdint.h).

The real problem is that a lot of the functions you would wish to call don't actually exist in the binary library you're linking against. Inline methods are frequently excluded as linkable targets, and you often don't want to link to them anyways, because they're meant to be inlined (think something like std::vector<T>::operator[]). On top of that, templated things are rarely instantiated (and have code generated for them) until their point of use).

Re:Speedy Desktop Apps with GTK and Rust by gmueckl on Saturday July 06, 2019 @04:44PM (#20371825)
Your list isn't even complete. Exception handling, deriving from C++ classes, RTTI etc. all add their own sets of challenges on top of what you have mentioned.
Re:Speedy Desktop Apps with GTK and Rust by Const-me on Saturday July 06, 2019 @06:48PM (#20372505)
Because it's so flexible, low-level in some parts (memory management, raw pointers) and high-level in others (template metaprogramming, lambdas).

If you restrict the API to a subset of the language, you can make C++ ABI just fine. My favorite style is abstract interfaces.

For the GUI example, look at WinRT. It exposes very high-level functionality, expressed in C++ as IUnknown-derived interfaces. These interfaces can be consumed or implemented by any compilers, or even other languages.

Such APIs work well even for very performance-critical code like DirectX or Direct2D. But there's downside, such APIs is not the most idiomatic form of C++: no exceptions, no iterators or other template shenanigans, no RTTI, no standard collections not even strings. All that stuff needs to be replaced with some equivalents.

When I only have C++ clients, I don't usually inherit from IUnknown, instead making an abstract base class with virtual destructor, and using std::unique_ptr smart pointers instead of CComPTR.

Re:Speedy Desktop Apps with GTK and Rust by KyleJ61782 on Saturday July 06, 2019 @10:21AM (#20369805)
Primarily it's due to function overloading. Different implementations may use different means to consistently and uniquely "mangle" function names on symbols to uniquely identify them in the library export. This mangling depends upon numerous factors, including parameter types and calling convention (if there are multiple conventions on a platform).
Re:Speedy Desktop Apps with GTK and Rust by fhcffg on Saturday July 06, 2019 @10:21AM (#20369809)
I think it’s because of name mangling (to enable polymorphism).

Name mangling wasn’t originally standardized, so every compiler did it differently, and now it’s too late to standardize.

Re:Speedy Desktop Apps with GTK and Rust by pjmlp on Monday July 08, 2019 @05:44AM (#20381254)
It has on Windows, initially via COM and now UWP, which is a revamped COM.
Re:Speedy Desktop Apps with GTK and Rust by pknopf on Saturday July 06, 2019 @09:06AM (#20369461)
It wasn't bad for me.

I wrote a .NET Core/QML interior layer.

https://github.com/qmlnet/qmlnet

Re:Speedy Desktop Apps with GTK and Rust by redblacktree15 on Saturday July 06, 2019 @09:07AM (#20369464)
It's just more work, because worst case you just need to wrap C++ APIs to C and bind that to rust.