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. Link from my program and .ui file
Forum Updated to NodeBB v4.3 + New Features

Link from my program and .ui file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 1.9k 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.
  • I Offline
    I Offline
    Ivan1120
    wrote on last edited by
    #1

    Dear all:
    I'm a newer in QT. I have a simple question. I added a item into my .ui file, why i can't use it's name of object in my program, do I miss something??Thanks for any answer.

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

      How did you try to use it?
      uic generated objects are accessible through the ui member, for example: if you create a label called myLabel in the editor it's accessible through ui.myLabel

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Ivan1120
        wrote on last edited by
        #3

        Firstly, thanks for your answer.Let me say detailed, I have "main.cpp", "mainwindow.cpp", "mainwindow.h
        ,"mainwindow.ui" now and I add a button called "pushButton" is located on [objectName] in "mainwindow.ui". Now, I want to access this button, but when I try to find name of this button in "main.cpp", I don't know what I should type, I can't find it in reference of typing.Can you give me some suggestions !? Thanks.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You won't find in main.cpp, the ui is related to your mainwindow.* files, it's there that you will code for it.

          In main.cpp you will essentially instantiate and show a MainWindow.

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Ivan1120
            wrote on last edited by
            #5

            Thanks. So If I want to describe some behavior of this button, like singal and slot, which file I can do that?? I found Items in .ui file are defined in "ui_mainwindow.h", should I write behavior of this button in this file!?

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

              No, the ui_mainwindow.h is generated by uic, and any changes you make there will be lost after recompiling.
              All your class related code should be in mainwindow.h and .cpp.
              If you want to expose some ui elements to outside classes create getters for them in your mainwindow class eg.
              @
              QLabel* getMyLabel() { return ui.myLabel; }
              @

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Ivan1120
                wrote on last edited by
                #7

                Thank you :)). I am successful.But I think It's a little inconvenient that compare to C# in .net framework.

                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