Simple GUI tasks (Well I need help!)
Hello, I am using the latest 5.01 version at home whilst my university has an older version which is causing issues when opening and compiling. That is a separate issue though.
I have a task which is to create a GUI application which displays a label marked “Size”, a lineEdit with the default value 50, and two buttons marked “Display” and “Step”. I have managed to do this:
"These should be placed in a vertical layout on the left. Use a spacer to stop the label getting too big.":
The bit I am stuck on is this: (I am guessing it is to do with signals and slots but I am not sure how to reset the text value?)
"Change the label text to “Hello world” when you click the “Display” button."
Take a look at step 9 "here":http://doc.qt.digia.com/qtcreator-2.4/creator-writing-program.html#designing-the-user-interface and then "here":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#text-prop
I am a bit confused by the second link.... I have done something like this.
It is an update() function too. ?
That's "almost" right ;) Think about it. If you had a couple of labels which would get updated if it worked like you wrote it?
You need to call setText on a specific instance, not on a class in general. Check in the properties panel what is the object name of your label and call setText on it.
It gives me a couple of errors.
:: is for when you call a static method on a class or in method definition or when you use namespaces. In case of class instance you use . (dot) and for pointers -> (this is your case).
I'd suggest going through a good C++ book and learning some language basics before you dive into Qt and UI programming. It would save you a lot of time and you could concentrate on the task instead of fighting with the syntax.
Oh I have done a year and a half of C++ dont worry about that haha... I know the basics. Never used Qt before this week though so have to get used to it.
Just getting confused by it. Havent used different class/function files for a while properly.
Still not quite working, not picking up my sizeLabel still... Undeclared, but I have changed it in the GUI view.
Still having issues. (Not looked since last night though)
Following errors ( I am not sure what is going on here as the properties name is sizeLabel so that should be it?)
Qt puts all the widgets created in designer as a children of the ui object, so it should be ui.sizeLabel->setText
Ahhhhh I see now. I think I will get used to the design view and code switch over after a bit more practise.
This was only a first task.
Thanks very much for your help. I am sure this forum will prove useful over the next few weeks.