247 points · by pjmlp · 7y ago · 181 comments
Yes! These two things are what's been on the very top of my wishlist ever since QML/QtQuick was first released.
In fact the QML format would not even be a terrible way to write non-UI applications, I'd think. Something like
MySqlDataBase {
id: default_db
host: ...
}
UserController {
items_per_page: 20
formatter: UserFormatter {}
repository: Repository {
table: "users"
database: default_db
}
}
is definitely more easier to follow than the linear version auto default_db = std::make_shared<MySqlDataBase>("...");
auto userformatter = std::make_shared<UserFormatter>();
auto repository = std::make_shared<Repository>("users", default_db);
auto controller = std::make_shared<UserController>(20, userformatter, repository);
especially when you do some kind of constructor injection with nested objects. The declarative tree structure of QML is great.(the QML structure only works as long as this is the case, e.g clear nesting of instances)
You can have references (default_db in the example) to instances to have indirectly nested instances too.
It’s selling point is that it works, and it does. Its a pragmatic choice.
I think this is one of those “join the crowd” things at this point.
Picking CMake for QT is a great decision.
...for personal projects, by all means take your pick, but bazel wasn’t ever really a contender in this space for them.
I wonder what's the Qt 6 road-map as C++20 is around the corner and is supposed to bring an amount of change similar to Qt 6, I presume. But basing on C++17 is already as new as it gets with their client base in embedded sector for example. Though it may be a bit too new. They can't lay dormant so it's a good deed after all, although timing seems unfortunate.
To the contrary - with modules more powerful build systems are needed that the ones which exist today. See this post for a CMake dev : https://www.reddit.com/r/cpp/comments/axnwiz/cmake_gcc_modul...
And some widgets are simply missing or accessible through obscure ways (e.g. instead of QSplitter being in the Containers group in the widget box, it is only accessible by ctrl+clicking two controls under a parent container that has no layout and right clicking and selecting selecting Layout horizontally/vertically (two menus) - WTF, what is wrong with simply letting me drop QSplitter in the form and then place controls manually? I can already do that perfectly fine after i perform the magic incantation to bring it in - though of course i cannot change the splitter position from within the form editor, because that would be too convenient i suppose).
I've seen form designers from open source projects written by a single developer in their free time that are more polished than that. The only thing worse is writing those UIs by hand.
Is there a reason Qt Designer generates .cpp files which append a child to the parent after the child is fully fleshed out, rather than when the child is first constructed? Does the latter approach create too many relayouts, or did it do that in the past? I tried to replicate that design quirk in my code, and had to use RAII to "add child to parent at end of scope", even though I don't want the destructors to run if an exception occurs during UI layout.
Focus QT! What do you want? Do that well.
Especially in automotive you’ll find that pretty much all media/entertainment functionality is running Qt, all the way through the stack.
Then again, its been ages that I had any use for Qt. Most of my work is backend or web and even mobile apps, which is something I would have considered Qt for in the past, I would now look into react native or PWA's.
Otherwise, yes Qt is the best option for cross platform C++ code.
https://devblogs.microsoft.com/dotnet/calling-all-net-deskto...
There were really fantastic Common Lisp bindings for Qt4, but they relied on a tool called "Smoke", which stopped working with Qt5. My understanding is Smoke was used to create the early Python binding, but a different mechanism was used for the Python bindings in Qt5. For some reason the new technique wasn't as easy to use from other languages, so a lot of alternative language bindings stagnated on Qt4.
I don't know if it's improved lately, but between using C++, the non-standard moc pre-processor, qmake, and little support from Qt itself, it's really hard to generate bindings for Qt now.
PyQt (Python) came from a small one man company in the UK called Riverbank Computing. It is mature and has been around for a long time. It used a custom tool called SIP for the bindings. Last time I checked it was still around.
In the Qt Nokia era, a team was assembled by Qt to create official Python bindings to compete with PyQt. IIRC they used Swig to do it. Then they lost funding for a few years before being revived in some form at which point they were busy moving to their own home grown binding generator.
At the moment Shiboken is more general, and mature and can be used even for C++ projects (which are not related to Qt). https://wiki.qt.io/Qt_for_Python/Shiboken
Qt has a massive uphill battle to try and stay relevant. Like it or not, there's a reason why electron apps and native ui sdks become the zeitgeist. While reusability is often cited as the main reason why electron has become the cross platform defacto, there's a lot more to it than that.
Personally, the difference between using electron and Qt is black and white. Looking at setting up alone, With Qt you have to struggle to compile a massive library which inevitably won't work. After sinking hours into compiling it, you're confronted with a unknown markup language and toolchain just to get a window displaying. And the documentation is incomplete, and to top it all off the minor versioning differences will cause your app to break in spectacular ways. Compare this to electron, where everything just works out the box, and with npm you have every single library you could ever think of. Microsoft and Apple roll out the red carpet for developers to make ui development super easy, so making two apps with a shared library is often just as tempting.
The way I'd try and save qt would be to make a react-native binding a first class citizen and ditch QML/js engines. I'd also remove the custom tool chains and release extensions for VSCode/Atom that outputted jsx that could get interoperated by a virtual dom. developers would kill for that.
Qt does not force you to use that language, the C++ API works fine and in my experience, the documentation has been one of the best I had the pleasure to work with.
"Microsoft and Apple roll out the red carpet for developers to make ui development super easy"
Microsoft I agree. Apple, on the other hard... Last time I checked (admittedly, a few years ago) there was no way to code an app without having a Mac hardware and a developer license. I ended up borrowing a friends' mac to compile... a Qt app. That worked immediately.
This has not been true for over 5 years.
Google Qt and OpenGL and you get the documentation of the appropriate widget. Google GL and electron and you get a bunch of github issues and people complaining it does not work well yet.
Nah, JS is struggling to get where Qt has been for years. I am happy that it solved its text alignment issue in 2014 though.
You mentioned "native UI SDKs" having become preferrable, but keep in mind that in many scenarios, Qt is the native UI.
On desktop Linux there isn't a lower level toolkit Qt is translating to, but also in the many embedded products Qt is used on: Car and aviation infotainment (a prominent example is Mercedes-Benz' MBUX OS, but there's literally dozens of these built on Qt and shipping), medical equipment, industrial machines (e.g. the entire HMI sector), kiosk systems, coffee makers, ... Qt is an excellent choice for these, often the only one, and the web stack is very unattractive there due to performance/hardware overhead, quality, security, etc. They're product use cases in industry, with a lot of available very high-paying jobs.
And it's worth keeping in mind that the use cases I cited above by and large pay better than making desktop software does today, unless you're an entrenched player like Autodesk (which uses Qt doe many of its apps). In the only "this pays for a decently sized staff of engineers" desktop app products that are new that I can think of, Qt is also still doing well - say, Pix4D's apps for drone mapping/photogrammetry - because they likewise solve hard problems where you don't want to deal with the web API abstraction/quality barrier and performance overhead.
My bottom line here is: Right now, and very likely ten years from now, if you are good at at Qt you're probably going to work in a very good and stable job at a solid business. I don't see this being the case for Electron developers, and I know where I'd rather be.
As for making desktop apps, if your experience is "Looking at setting up alone, With Qt you have to struggle to compile a massive library which inevitably won't work" it shouldn't be ignored and the developer experience should be improved - tooling, build system and getting modules to devs are all mentioned in this blog. However, I have to say this has never been my experience - between Qt being packaged in Linux distros and the SDK installer on other platforms it's never been hard to set up Qt for me.
What?! If you're specialising in Qt then your skills are tied to Qt and you are tied to the health of the Qt job market. Those skills are not very transferable. On the other hand, 90% of the skills needed for Electron development are web technologies which are relevant to the massive web related job market. I know where I'd rather be.
This isn't how it shakes out in practice, though. If you're "specializing in Qt", what you really become is a GUI systems engineer who in the course of their career will learn the fundamentals of many of the things this entails. You'll be the person that knows how the browser works and how to write it, not the person who is beholden to its crummy abstractions on top of better APIs. Case in point - the Chromium/Blink engine used by Electron was originally a Qt codebase (KHTML).
Most Qt engineers I know have a lot more fundamental, transferable knowledge than the web engineers I know.
I think you are very wrong. Qt is just a bunch of C++ with preprocessing. Knowing C++ is a very transferable skill.
What's going on there is that for that lucrative OEM product market I mentioned, it's a very attractive quality of Qt that their developers can test builds (of what is technical not a desktop app as it doesn't aim to integrate with the host platform) on their desktop system instead of having to remote-deploy to the embedded device or spin up an emulator for every change (cf. https://www.youtube.com/watch?v=EswaK8hTonA&t=42s). A lot of Qt's lesser competitors in the domain don't offer this to the same extent.
The other reason is that the desktop is very important as a recruitment vector for the companies that end up picking Qt partly because of the quality of the developer talent available. Not every young developer has access to a car infotainment test rig, but they have access to a desktop system; Qt needs to be on the desktop to allow you to learn it with just a desktop system. Plus open source communities like KDE that make a lot of desktop and mobile software act as a breeding ground for talented devs.
Portability is in many ways about Qt not narrowing into a specialist/niche product, many of which it outcompetes in domains where it's the best option. So it is critical, but it's critical to avoid that slippery slope that would eventually hurt the markets that keep it afloat, even if not all the platforms equally bring in the money all times. It's about generality as a feature for a healthy systems technology.
I'm not sure if you have used Qt recently based on this description. There is no need to build it from source, just use the installer, then launch QtCreator, everything just works, on win, linux and mac.
The Qt document is the best I have ever seen.
why would you have to compile Qt if you just want to make an app ?
Electron apps generally have no accessibility consideration, and accessibility is often the cornerstone of usability. Especially for keyboard users.
Additionally, their performance is abysmal. Even the latest Slack update, which was focused on improving performance, see Slack using more CPU than my Java-based IDE (Jetbrains) sometimes.
Electron has 700% performance lost over UWP/C++, which is the baseline.
Expect similar results when comparing against Qt.
... Performance is terrible on a quad-core i5 notebook with 16gb of ram and a gtx 1060 graphics card... I am talking about dragging the first element on an empty canvas and resizing it.
Hopefully Electron will improve - more choices are always nice.
But then again, Electron is based on Chromium and Node.js, both are "C++-based". Improvements in those C++ codebases and improvements in C++ compilers will probably also lead to better performance in Electron itself.
I use nw.js which is similar to Electron for a UI that also allows dragging shapes and text around. It's SVG-based and it's stupid inefficient-- for every mousemove event I'm sending coords over the socket to a backend and receiving back a message that triggers a callback to do the actual property/attribute updates to the respective DOM elements. In other words, I'm using the browser's slowest graphics API in such a way that any layout changes are guaranteed to trigger the least performant graphics updates.
Still it performs just fine on a Lenovo from 2006.
What you are probably seeing is that the Electron GUI toolkit allows devs to throw together a GUI so quickly that they can ship a product in the time it takes to read the documentation of other GUI toolkits. You may thus be comparing a class of cross-platform applications in Electron which simply don't/can't exist in other GUI toolkits given the same amount of effort.
If not for developer experience, why is electron ever used for anything?
There's no technical merit to Electron.
Also portability from a popular platform is a technical merit.
That Qt is better on its own is also a merit, but not the only one.
This list[1] is out-dated (spotify uses electron, for example). But after skimming it I don't recognize any big software applications that have an exceptional user experience. Some, like Google Earth and Calibre are abysmal at best.
[1]: https://en.wikipedia.org/wiki/Category:Software_that_uses_Qt
https://gitlab.com/rhn/rust-qt-bindings-generator
It's for Qt5, and I think I know how to achieve strong typing (just turn everything into different QObjects, they don't get converted), but haven't implemented that idea yet.
I'm no UI designer/programmer, but it seems to me that Qt being apparently very dependant on C++'s object oriented concepts seems to make integration with Rust very difficult, since Rust very much does not follow's C++ concepts of objects and classes.
I just hope they gonna keep memory footprint as low as possible so I can keep bashing electron devs.
well, they want to focus on microcontrollers apparently :-)
And due to C++ API, Qt has poor language bindings, compared to GTK and many others with C API.
Declarative UI languages do have some advantages compared to regular programming languages, but that's unrelated to the claim you made.
Bindings are not C++'s problem, they're the problem of the other languages which try to use UI frameworks written in C++, like Rust, which still doesn't have any decent UI library.
That may be true for Python, but the Common Lisp bindings for Qt4 were equally as "powerful" as the C++ bindings. It had higher level abstractions that generally made it easier to read and write, as well.
> Bindings are not C++'s problem
Actually, bindings are a problem with C++. Some features (like templates) and implementation details (like name mangling) make it very difficult to create bindings to C++.
QML, Swift, Android, UWP, WPF, Forms, Blueprints, Unity, React Native.
I agree, not necessarily with c++ but it's much better to build UI's with code than declarative xml crap.
It will be a shame if Qt sticks to a pure c++ interface though, I'd hope the build something more usable from more languages so it's an option for C, Zig, Rust, etc.
Why? And why are scripting languages better?
It's okay to have expensive abstractions where a few milliseconds simply don't matter, but tasks can be done in minutes instead of hours. Declarative UI descriptions also have the benefit of being friendly to visual designer applications, so you need fewer build/run/test cycles (which are far from quick with C++).
Most of this is no longer as relevant in C++, can't speak for Rust. Programming languages have been converging for quite some time, C++ of today is more dynamic and convenient than any version that came before.
That being said, you can't beat dynamic languages for some tasks. Runtime code generation/eval being the most obvious I can think of. Any kind of extension/plugin architecture has everything to win from going all in with a full scripting language from my experience.
Microsoft is the only consumer OS vendor that still supports C++ for doing full stack GUI apps, everyone else moved into a mix of C++ plus managed language or layout DSL.
So for targeting X11/Wayland or Windows, you can bet 100% on C++, only Apple platforms do not offer native C++.
Which UNIX OS SDK uses a C++ GUI full stack?
One could argue for Kubuntu or SuSE, maybe, except KDE isn't tied to a specific OS and then again it uses Qt alongside QML since Plasma, so no pure C++ stack here.
And since you missed to fully read my comment, here it is again:
> Microsoft is the only consumer OS vendor that still supports C++ for doing full stack GUI apps
On modern Windows you have C++, and also layout DSL, specifically XAML. And that C++ is not particularly idiomatic, it’s IUnknown-derived interfaces.
If you mean windows desktop, WinAPI uses quite a few DSLs. Dialog and menu resources are the most obvious, but there’s more: WMF/EMF vector graphics format, ribbon markup XML for ribbon control, theme files…
Modern Windows desktop UI, UWP aka WinUI, uses C++17 with a framework called C++/WinRT, that hides those IInspectable COM interfaces.
Yes there used to exit C++/CX and Windows Runtime Library, both now considered legacy and replaced by C++/WinRT.
Plus ca change…
https://doc.qt.io/archives/qt-5.11/qtquickcontrols2-flatstyl...
Then before the engine is loaded in main.cpp call
qmlRegisterSingleton( QUrl(QStringLiteral("qrc:/Theme.qml")), "mycustomname.theme", 1, 0, "Theme");
Then in a qml file:
import mycustomname.theme 1.0
This allows you to do something like:
Rectangle { width: 100 height: 100 color: Theme.mainColor }
You can also do things like set the application font which would be done in main.cpp before the engine is loaded:
QFont appFont("NameOfLoadedFont); appFont.setPixelSize(16); QGuiApplication::setFont(appFont);
You would need to load the font, which you can do in the Theme.qml file:
property FontLoader someFont: FontLoader { source: "qrc:/locationOfFont/Font" name: "NameOfLoadedFont" }
Web Assembly QT enables a really nice way for customers to mess with an app without installing anything on their systems. It works with Q5\, but a still has much to be improved.
\
with a bit of modification to QT's output.If they streamlined the licensing and created (C)sensible language bindings then it would be great. I tried the python bindings and they were problematic. Can't even imagine using one of the unsupported bindings.
They made a choice that was good for local rendering but because it sends full bitmaps to the X server to display it uses a lot of bandwidth which killed performance when forwarding X applications over the network.
I'm personally of the opinion that today's X is only accidentally network transparent and a bad remote desktop solution but I don't deny that it's part of a lot of peoples' workflows.
It won't be soon, either. Qt is aiming for a first release of Qt 6 by the end of 2020.
GUI frameworks have usually been tied to inheritance-based object oriented systems.
During the early days of GUI development, immediate mode won because scene graphs are more demanding in regards to memory consumption, and graphic chips were quite limited anyway.
Please show me one major new desktop application written today which uses Qt. Major meaning used by millions of people.
These apps seem to be popular with device manufacturers. I have the displeasure of using two such apps, both have crap usability and custom UIs that don't make any effort to integrate with the platform. One of them doesn't even respond to the quit shortcut.
All apps written by device manufacturers are crap, regardless of what they are written in. It has nothing to do with Electron, just with the fact that they only know how to do hardware, and are clueless on the software side.
It's modern looking, but obviously not native and doesn't respect some platform idioms or shortcuts, so all in all it's a subpar experience. This is completely related to Electron and would not happen for a native app, where the framework takes care of the look & feel and integration.
If every app were written like this, we'd end up with scores of slightly inconsistent apps, all of them trying to be unique and cool and resulting in a mediocre platform. i.e. Windows.
And what an amazing time that was.
As too often for a Qt application, the interface looks alien on macOS.
But easily, Skype.