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. How to use the contents of an object from MainWindow to another window?
Forum Updated to NodeBB v4.3 + New Features

How to use the contents of an object from MainWindow to another window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 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.
  • rafael01justinoR Offline
    rafael01justinoR Offline
    rafael01justino
    wrote on last edited by
    #1

    **I have a MainWindow with a LineEdit and have another window with a Label. I want to use the contents of LineEdit of MainWindow in Label of the another window.

    In short, I would like to know how to use the content of an object from a window in another object of another window.

    PS: I am a beginner in QT, please explain in detail step by step how I include this object.

    Tnks!**

    Ni.SumiN 1 Reply Last reply
    0
    • rafael01justinoR rafael01justino

      **I have a MainWindow with a LineEdit and have another window with a Label. I want to use the contents of LineEdit of MainWindow in Label of the another window.

      In short, I would like to know how to use the content of an object from a window in another object of another window.

      PS: I am a beginner in QT, please explain in detail step by step how I include this object.

      Tnks!**

      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      @rafael01justino

      you have to use signal and slot mechanism. This example has given more info, about accessing ui components from other class. IF you don't get it, just let me now. I can make small sample for you.

      rafael01justinoR 1 Reply Last reply
      2
      • Ni.SumiN Ni.Sumi

        @rafael01justino

        you have to use signal and slot mechanism. This example has given more info, about accessing ui components from other class. IF you don't get it, just let me now. I can make small sample for you.

        rafael01justinoR Offline
        rafael01justinoR Offline
        rafael01justino
        wrote on last edited by
        #3

        @Ni.Sumi I read the two links, but did not quite understand.
        Could you give an example, step by step, using a LineEdit and a Label in different windows?
        Thanks!

        jsulmJ Ni.SumiN 2 Replies Last reply
        0
        • rafael01justinoR rafael01justino

          @Ni.Sumi I read the two links, but did not quite understand.
          Could you give an example, step by step, using a LineEdit and a Label in different windows?
          Thanks!

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @rafael01justino You should really learn signals/slots concept, else you will not be able to do much with Qt as it is one of the core concepts.
          In this case you probably do not have to use signals/slots. If your main windows creates that another windows then it can set its label. But if you want to change that label when the line edit is changed then you should use signals slots.
          QLineEdit has some signals, you can use http://doc.qt.io/qt-5/qlineedit.html#textChanged . Connect it to setText(QString) slot of your QLabel: http://doc.qt.io/qt-5/qlabel.html#text-prop

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • rafael01justinoR rafael01justino

            @Ni.Sumi I read the two links, but did not quite understand.
            Could you give an example, step by step, using a LineEdit and a Label in different windows?
            Thanks!

            Ni.SumiN Offline
            Ni.SumiN Offline
            Ni.Sumi
            wrote on last edited by Ni.Sumi
            #5

            @rafael01justino

            Here, I made a sample. Please download it here this and try to implement this to your case. This is just rough way to do, I have made two mainwindows. MWindow1 has label, line edit and oush button. click on the pushButton , it opens the second window and write some text in the lineEdit. I made two connect()'s , one is to connect to the label and lineEdit in the same class and other is to connect in other class.

            I request you also, to read completely the signal and slot mechanism, as @jsulm mentioned.

            Remember, I made it roughly, you should implement the same according to your project/code.
            Note: I have used connect in 4.8 and 5.5 way, you can also check the latest signal and slot mechanism in Qt5.7.

            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