QT widgets tutorial
-
Is it me, or does the first page of the tutorial not make any sense? I'm trying to follow the instructions at: https://doc.qt.io/qt-5/qtwidgets-tutorials-notepad-example.html
I'm new to Qt and trying to work out how to use it for applications and how to use the IDE.
Having followed the instructions in Designing a UI --> Using Qt Designer, the section Notepad Header File states that the wizard should have created a header file with a whole bunch of information in it, but mine has nothing in it except for a minimal class declaration with just the Q_OBJECT macro, a constructor declaration, a destructor declaration and a private Ui::Notepad member.
Similarly, the source file has about 15 lines in it as opposed to the very large file displayed in the tutorial.
It must be me, but can anyone tell me what I'm missing, please?
-
Hi and welcome to the forums.
its just in an odd order. they explain how the UI files work first
but its actually first in section
Adding User Interaction
where they talk about using Goto Slot to have it generate slot for the buttons and menus.
So just keep reading and it should be fine. -
@peredur
Np :) Actually it has been asked before as the tutorial reads funny as they show
the .h file with all the added slots but just after running the wizard, that's not what you have at that point which naturally is confusing. -
@mrjj And I have to confess that I still don't get it. The Adding User Interaction section starts of by saying: "Click on "Type Here", and add the options New, Open, Save, Save as, Print and Exit." But this doesn't make any sense either since the illustrations show top level menu items of "Fill" and "Edit". So shouldn't those be added first?
Then the tutorial moves on to say that we'll fill in the newDocument() method. But where has that come from?
I know that asking this is very risky, but am I particularly stupid? I really can't follow this tutorial at all.
:(
-
Hi
Nope, the tut could have described in more details how and where to click.
I recall that at some point, the Application template might have been more like in the tut
and not as bare bone as its now. Maybe that is why there seems steps missing.And you are right, you have to fill out the Top level menus first, to add the submenus
After you type at "type here", an action is added to the action editor below the form
You can then RIGHT click the action,
and you find the Goto Slot there
where you select the signal to create the slot for.
(the slot being your function to call when the menu (the action) is activated. (clicked)
and then create the slot to be filled out
However, in the tut, the seems to have the slot typed in manually. ( or it was another wizard at some point)
Adding a slot is just like adding a member function to the .h/cpp file but just listed under slots.private slots:
void newDocument();and its then manually connect to the action
connect(ui->actionNew, &QAction::triggered, this, &Notepad::newDocument);
(this is like using Goto Slot but connected from code instead, which is recommended for real apps. )
The connect line says
connect the actionNew triggered signal to the newDocument slot.
so its much the same as using Goto Slot menu but done from code.So I guess at some point the New Application Wizard would create such notepad like the sample
in tut but now only creates a barebone MainWindow project. ( or i missed something obvious)
So i think that is why it feels a bit off trying to follow.However, you can add some of the actions and slot and fill out as they say.
(using Type Here and Goto Slot)