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. Passing Variable Between Forms

Passing Variable Between Forms

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 902 Views
  • 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.
  • U Offline
    U Offline
    UrsaTempest
    wrote on 28 Mar 2019, 04:23 last edited by
    #1

    I have two forms. Form one, call it Form1, is asking for name, age, etc. With a button, where user can click on it and it'll be imported to appropriate variable. Form2 shows the variable submitted via Form1, like Name: [Name], Place of Birth: [Place], etc.

    Despite many tries, I can't seem to implement this. I've read enough apparently I'm supposed to use Signal and Slot to do this, but I can't seem to grok this. Like, at all. How do I achieve this?

    J 1 Reply Last reply 28 Mar 2019, 05:20
    0
    • U UrsaTempest
      28 Mar 2019, 04:23

      I have two forms. Form one, call it Form1, is asking for name, age, etc. With a button, where user can click on it and it'll be imported to appropriate variable. Form2 shows the variable submitted via Form1, like Name: [Name], Place of Birth: [Place], etc.

      Despite many tries, I can't seem to implement this. I've read enough apparently I'm supposed to use Signal and Slot to do this, but I can't seem to grok this. Like, at all. How do I achieve this?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 28 Mar 2019, 05:20 last edited by
      #2

      @UrsaTempest What did you try and what were the issues?
      For this you define a signal in Form1 and in Form2 you define a slot. Then in your main window (or wherever you create both forms) you connect the signal to the slot. Form1 emits the signal as soon as the data is entered and Form2 puts the values into its UI.

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

      1 Reply Last reply
      1
      • U Offline
        U Offline
        UrsaTempest
        wrote on 28 Mar 2019, 05:36 last edited by
        #3

        First I try using variable like in my OP post, then I try to grok signal and slot. Though, hm.

        I think I sort-of got your explanation? I think. Will try it later today.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          UrsaTempest
          wrote on 28 Mar 2019, 06:02 last edited by
          #4

          Right, now I remember my difficulty.
          I can sorta understand how signal and slot works - signal emits signal, slot receive signal. But of the example I read, I don't know how to put the value into slot.

          Like, I create public slots on Form2.h, named them name_write, and dob_write. Then I go to Form2.cpp. Form2.cpp has two labels for showing input, name_display and dob_display.

          My difficulty is I don't know how to use signal and slot to change those label to whatever the user put as input.

          J 1 Reply Last reply 28 Mar 2019, 06:09
          0
          • U UrsaTempest
            28 Mar 2019, 06:02

            Right, now I remember my difficulty.
            I can sorta understand how signal and slot works - signal emits signal, slot receive signal. But of the example I read, I don't know how to put the value into slot.

            Like, I create public slots on Form2.h, named them name_write, and dob_write. Then I go to Form2.cpp. Form2.cpp has two labels for showing input, name_display and dob_display.

            My difficulty is I don't know how to use signal and slot to change those label to whatever the user put as input.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 28 Mar 2019, 06:09 last edited by
            #5

            @UrsaTempest The values are passed as parameters:

            class Form1
            {
            signals:
                void someSignal(int value);
            }
            
            class Form2
            {
            public slots:
                void someSlot(int value);
            }
            
            // Then in Form1 you emit the signal
            emit someSignal(10);
            

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

            1 Reply Last reply
            4

            1/5

            28 Mar 2019, 04:23

            • Login

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