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. About the ui object and what it holds

About the ui object and what it holds

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 1.7k 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.
  • P Offline
    P Offline
    Project try
    wrote on last edited by
    #1

    Hey guys , i'm using the newest qt creator , and i'm new to this I got 3 question , if you guys can help me with it ^^

    1- the ui object , when I try to access classes , what does it include ? and can I access stuff without the ui object ?

    2- when I try to do this " ui->pushbutton->settext(...);
    is this going to set all push buttons to the name that I've put in the arguments ?

    3- what's the difference between renaming it in the edit widget and the function above ?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      HI,
      Welcome to Qt-project forum.
      If using designer the ui object holds all your GUI elements that you created with designer. The MOC compiler will generate a mainwindow_ui.h file in the background that will construct a ui class object.
      In the beginning of your main window class you will see @ui(new Ui::MainWindow)@ which is the same as: Setup the pointer ui to the constructor of the Ui::MainWindow class
      The @ui->setupUi(this)@ will allocate all needed memory for the GUI elements.
      1: Without the ui object you can't access your GUI elements!!
      2: No, it will only set the text of the pushButton with the objectName: pushButton. In designer the next pushButton will get ObjectName: pushButton_2 and so on and on. It is my recommendation to rename them
      3: Renaming the widget in designer is compile time, setting the text in the setText() function is runtime, but the result is the same.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Project try
        wrote on last edited by
        #3

        Thanks man , so about the pushbutton , it's all depends on the order ? for example if I put two pushbutton , and called settext("ok"), and the next one settext(" not ok ") , the first one will get the name " ok " and second " not ok " ? and we can apply it on things beside settext ?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Project try
          wrote on last edited by
          #4

          ah , I just tried adding a second one and there was " pushButton_2 " :D

          thank you ^^

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            ;-) Like in any C++ class you may not have two the same identifiers
            What you could do, but that might be a bit to advanced for now is to get the ui pointer and get all children (QObject function) and do a dynamic cast to a QPushButton, if succesfull do the setText function with a counter value. If you really need to do it run time.

            Greetz, Jeroen

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Project try
              wrote on last edited by
              #6

              Thanks man , I'm really upset , when I tried to create a simple program I couldn't have done it , it seems that it still confuses me I just finished learning about signal and slot :(

              is there a website that gives you a simple problems that you can solve ?

              1 Reply Last reply
              0
              • JeroentjehomeJ Offline
                JeroentjehomeJ Offline
                Jeroentjehome
                wrote on last edited by
                #7

                This forum is a good start if you encounter problems. There are more then enough guys here to help you.
                There is a 'how to learn Qt' doc on this site somewhere if you need some assistance.

                Greetz, Jeroen

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  ankursaxena
                  wrote on last edited by
                  #8
                  1. Yes.!! U can access the all the widgets or stuffs with out using Ui. but for that u have to do some changes in header file as well as .cpp file.

                  2. No. It do not set all push buttons to the name that u've put in the arguments

                  3. The difference between renaming and settext() method is that when u use rename . It change name of the object but settext() just use to write any text on it. So u can write same text on two buttons but name of the two buttons must be different.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ankursaxena
                    wrote on last edited by
                    #9

                    When U will write "Ui->" then it automatically show the name of the all objects.

                    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