[Interest] Guide me through the Qt offerings for GUIs

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Thu Apr 22 18:17:36 CEST 2021


On 22/04/2021 17:06, Rui Oliveira wrote:
> Q_INVOKABLE, Q_PROPERTY, etc... The Qt stuff crawls into what would 
> otherwise be just business logic because you need to access something.
> 
> I've linked this before: 
> https://stackoverflow.com/questions/66618613/qml-c-classes-with-bring-your-own-component
> 
> Which again, is absolutely trivial do to with C++ and polymorphism. And 
> a pointer/reference instead of adding macros in 20 placesĀ  and the 
> Q_PROPERTY lines...
> 
> Basically we're coupling the whole backend to the GUI framework.
> 

Wait, this sounds precisely what you shouldn't do.

You should create a C++ layer (call it a "presentation" layer) that sits 
between your (possibly non-Qt) business logic and the UI. That layer 
contains stuff like item models, QObjects that expose the relevant 
business logic APIs, type wrappers, and so on.

(Possibly even more layers. Like an cake. Or an ogre)

This way

* the business logic is agnostic of the UI framework used above (could 
be Widgets, could be Qt Quick, could be HTML)

* you can do UI testing by swapping out the business logic with a 
testing one

* you can test the business logic without the UI

and so on.


While building this layering may be super tedious (YMMV), in the long 
run, it makes your application more robust, not less. The fact that QML 
_forces_ you to have this stuff becomes somehow a good thing.


On widgets, well, raise your hand if you didn't at least once connect a 
QPushButton to a slot declared in the widget that contains the button, 
and perform some business logic from there (yay business logic in the UI!).

And/or thought "ok, I should add a controller for the UI layer that 
talks to these other 5 objects, and does this and that, and gets 
triggered by the button... or I could just #include 
"Component_Deep_Into_Business_Logic.h" and just call a method on it.". 
You know, "a little goto never hurt anyone". (Velociraptor ensues)


In other words, being "entirely" in C++ has also its downsides.

HTH,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210422/fbddaa8c/attachment.bin>


More information about the Interest mailing list