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. Is possible in Qt change a value or property of a parent widget?
Forum Updated to NodeBB v4.3 + New Features

Is possible in Qt change a value or property of a parent widget?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 4.3k 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
    ArcNexus
    wrote on last edited by
    #1

    Hi All!!

    A beginner with a problem :-(

    Is possible from a Dialog, alter a value of a widget in its MainWindow? and... know a value of widget in mainwindow? or only is possible with parameters and return value between MainWindow and Dialog?

    If is possible please can you tell me how I do it in Qt?

    Thanks.

    When we are one, we win

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wwwcs59
      wrote on last edited by
      #2

      As I know is using the signal and slot

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mkuettler
        wrote on last edited by
        #3

        Hello.

        It is possible to excess other widgets from a dialog. There are multiple ways to do so:

        You can connect a signal from the dialog with a slot in an other widget. This has the advantage that the dialog itself does not need to know about the any other widgets, it just notifies the world around it that something happened, and everybody who wants to react to this needs to be connected to the signal. This way you cannot read a value from an other widget though (unless the widget sends a signal that is connected to a slot in the dialog, but that requires the widget to know that somebody else wants some information right now, which might or might not be what you want).

        If you can modify the behavior of the dialog directly (i.e. if you inherited from QDialog somehow) then you can call whatever function on other widgets you like. For that the dialog needs to know the other widget of course. So you either have to pass the widget to the dialog (e.g. to your custom constructor), or you could use the QDialog's parent() method to navigate up in your widget hierarchy and find the widget you want.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          David_Gil
          wrote on last edited by
          #4

          For example, in the constructor of the dialog you can connect the signal valueChanged to the slot setValue of mainWindow. It can be an integer or whatever value type you need.

          @
          connect(dialog, SIGNAL(valueChanged(int)), mainWindow, SLOT(setValue(int)));
          @

          Then, when you need the dialog to emit the signal, just type:

          @emit valueChanged(value);@

          Remember that you have to create those signals and slots if the classes you use don't have them. It's easy and very powerful.

          More information: http://qt-project.org/doc/qt-4.8/signalsandslots.html

          I hope it helps!

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

            [quote author="David_Gil" date="1339400872"]For example, in the constructor of the dialog you can connect the signal valueChanged to the slot setValue of mainWindow. It can be an integer or whatever value type you need.

            @
            connect(dialog, SIGNAL(valueChanged(int)), mainWindow, SLOT(setValue(int)));
            @

            Then, when you need the dialog to emit the signal, just type:

            @emit valueChanged(value);@

            Remember that you have to create those signals and slots if the classes you use don't have them. It's easy and very powerful.

            More information: http://qt-project.org/doc/qt-4.8/signalsandslots.html

            I hope it helps!
            [/quote]

            I think its just I need Thank's a lot!

            When we are one, we win

            1 Reply Last reply
            0
            • M Offline
              M Offline
              miroslav
              wrote on last edited by
              #6

              Note that if you are asking about properties, most experienced Qt developers will think if QObject properties, maybe even the dynamic kind (I certainly did). Those are a different kind of beast. In your case, the signal-slot mechanism is what you need.

              Mirko Boehm | mirko@kde.org | KDE e.V.
              FSFE Fellow
              Qt Certified Specialist

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

                [quote author="miroslav" date="1339487318"]Note that if you are asking about properties, most experienced Qt developers will think if QObject properties, maybe even the dynamic kind (I certainly did). Those are a different kind of beast. In your case, the signal-slot mechanism is what you need.[/quote]

                Yes, in this moment this is all I need; but in the future....... ;-)

                When we are one, we win

                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