Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Simple GUI tasks (Well I need help!)
Forum Updated to NodeBB v4.3 + New Features

Simple GUI tasks (Well I need help!)

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aaronjlaw
    wrote on last edited by
    #1

    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:
    !http://img.photobucket.com/albums/v334/Klaus5000/1gui_zps39dd3e4a.png()!

    "These should be placed in a vertical layout on the left. Use a spacer to stop the label getting too big.":
    !http://img.photobucket.com/albums/v334/Klaus5000/blahhh_zps24f24e55.png()!

    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."

    Any pointers?

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aaronjlaw
        wrote on last edited by
        #3

        Hello there,

        I am a bit confused by the second link.... I have done something like this.

        void MainWindow::on_displayButton_clicked()
        {
        QLabel::setText("Hello World");
        }

        It is an update() function too. ?

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aaronjlaw
            wrote on last edited by
            #5

            It gives me a couple of errors.

            EDIT:
            void MainWindow::on_displayButton_clicked()
            {
            sizeLabel::setText("Hello World");
            }

            1 Reply Last reply
            0
            • Chris KawaC Online
              Chris KawaC Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              :: 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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aaronjlaw
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  aaronjlaw
                  wrote on last edited by
                  #8

                  Still having issues. (Not looked since last night though)

                  void MainWindow::on_displayButton_clicked()
                  {
                  sizeLabel->setText("Hello World");
                  }

                  Following errors ( I am not sure what is going on here as the properties name is sizeLabel so that should be it?)

                  !http://i49.tinypic.com/2v3ljpg.png()!

                  1 Reply Last reply
                  0
                  • Chris KawaC Online
                    Chris KawaC Online
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Qt puts all the widgets created in designer as a children of the ui object, so it should be ui.sizeLabel->setText

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      aaronjlaw
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved