Qt World Summit: Submit your Presentation

How to properly architect a Qt desktop application?

  • Hello!

    I have very little experience with .NET WPF. Now I decided to try Qt because of the use of C++ here (I want to go further into this language).

    Now I’m faced with the problem of building an architecture for a future application. I want to plan how components will interact with other in the app. For the first application I chose the snake game with speed and mode (solid borders or not) settings, which means at least 2 windows (startup window with settings and game window).

    WPF uses Movel-View-ViewModel architecture extensively. I’m not very good at it, as I am not very good at architectural solutions. But I know there it is implemented through a data binding system called "bindings". So View is the visual part of the application, in WPF it’s a XAML layout. This View "connects" to a specific data context for this View - to the ViewModel. Also, there is the Model. I didn’t really get the gist of the model, but I understand it to contain data properties. So if I have some text in WPF, and also, say, a slider, then using bindings I can bind them. So if I move the slider, it changes the value of the property that is associated with the text. And the text will automatically change when you move the slider to the current slider value. Well, it’s just an example of how you can use this architecture and what the WPF platform gives you to work with it. And you can use that to communicate across classes and so on. In Qt, I understand, there are no such bindings.

    So my question is. How do I implement architecture, communication between different classes and windows in Qt Widgets more correctly?

    If I want to create an user interface through code ( What do experienced qt programmers think - is it worth using a designer? I personally don't like it.), then I need some View as in WPF? How can it be linked to implementation? Where should the basic logic be placed and how to interact it with other components (or other components with it) of the project?

    Maybe you can give me some advice, given the context - the snake game?

    I hope I have made myself clear. But if anything remains unclear, please let me know and I will try to explain the details as soon as possible. Thank you!

  • @mingvv

    First, you should understand the basics of C++ and object-oriented programming in general. Without it's really hard to get a satisfying result and you will spend most of your time looking for things or trying to figure out how things work (or why they don't).

    Qt also has Model-View based classes.

    You can communicate with your GUI or other QObject classes using the Qt signal&slot system or using events.
    For example if you press a button, you will emit the clicked signal. Then, if you connect a slot (= function) to this signal, the function will be called to perform some actions.

    A (simple) snake game in Qt might be a practice to start with. Think about what classes / structure you will need, design your GUI and start writing your code :)

    Might be helpful:

    According the "GUI Code vs Designer" thing:
    It's mostly a mix of both. Some things just can't be done using the QtDesigner, but it helps a lot creating your basic widgets and your basic design.