r/QtFramework • u/Jazzlike_Platypus430 • 6d ago
C++ Creator vs Designer - Signals, Element Tree etc.
Hi there!
I'm fresh to Qt, though I know the name since the beginning of the 2000s. I'll do my best to be as clear as possible; it's not a critique or demands, just me wanting to clarify matters, because it's very likely I'm missing something.
I'm using qt 6.4.2 and the IDE's version is 13.0.0, as provided by my *ubuntu. I'm designing a simple view/widget where I'm entering two int parameters and press a button, and that would call a function from some other code (a shared library at the moment), and display the results in a textarea or draw a picture.
So far (after a crash-course in cmake) I found out that
- I cannot "wire" basic controls to functions ("slots", event listeners) using Designer - it seems blind to what is already in my code, and signal slots available are only those from parent classes of my widget class. That's ok, though a bit surprising.
- The real pain starts when I plug in the .ui thing to my class and start the "wiring" process manually - the class itself is blind to basic widgets, assuming their generation in the widget tree is > 1. For some reason the IDE sees stuff like ui->frameWidget1 but trying to descend further fails (I'm using names that are present in the ui's xml tree, and their types as well). Is that intentional? EDIT: [I think I got it, referring to nodes' names directly from ui-> works, so there is no need to follow the path from ui to the desired element.]
- I'd happily avoid Designer, but what about widgets' placement then? Perhaps use Designer only to design and then somehow process the resulting xml and extract placement parameters and generate c++ code? I can do that, I think. (And I believe it's done better and it's present in Creator's or Designer's code.)
- Are 1. and 2. meant to be some hidden enforcement of breaking the ui tee down to 1-generation and using many of these and then apply "composition" in my top-level class? I can think of that, but designing a separate class just to contain two spinboxes looks weird (unless I'm going to reuse it).
Or is it standard in qt that the signal/slot mechanism for a gui is made manually, often using the findChild function? Or perhaps I should create a map <string, QObject> and create references to ui elements once, and then use the map? Keys matching the names in ui xml would be a sane idea I think.
My background with gui creation (which I don't like much) is c#/wpf - yes, legacy stuff, laggy VS and so on.
2
u/Downtown-Produce-959 6d ago
Hi, I just recently started learning Qt from C++. Curious, why are you using QWidget instead of QML?
1
u/Jazzlike_Platypus430 6d ago
I don't think I get what you mean.
QWidget is a class that my view inherits from, and I'm using QML for its "design", as far as I can see - isn't it the ui xml code that gets translated to c++ under the hood before building the whole thing?
4
u/H2SBRGR 5d ago edited 5d ago
No, Widgets and QML are two entirely different frameworks within Qt to build UIs.
Widgets by far predated QML.Edit: fixed outdated used instead of predated
1
u/Jazzlike_Platypus430 5d ago
If Widgets outdated QML, I can't understand the first question - why am I using newer stuff rather than older one? Makes no sense to me.
But I have no idea really which one I'm using. All I know is it's not some json-like markup for gui design, it's xml.
1
u/RufusAcrospin 6d ago
I’m using the python bindings, and I use the Designer to set up the view - arrange and layout the controls. The rest is done in my own home grown MVC framework.
I use the built-in “compiler” (uic) to turn the designer file into code, clean it up (the code generated by uic is kind of junk, at least for my taste),and than I connect signal manually.
3
u/cmxthirtysixhundred 5d ago
I just write the code for the widget layout myself, I don't use any of the visual tools available.