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. Variable value sharing between Classes
Forum Updated to NodeBB v4.3 + New Features

Variable value sharing between Classes

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 395 Views 2 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.
  • ahsan737A Offline
    ahsan737A Offline
    ahsan737
    wrote on last edited by
    #1

    Greetings,
    I have written 2 classes, one class establishes a Bluetooth connection and reading incoming, second class is displaying bar graph (dynamic update) corresponding to incoming values over Bluetooth connection. My question is how can I share/pass incoming values from one class to the other?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      I have a suspicion that your question is deeper than simply sharing data between classes, but that you don't know how to properly ask it.

      The signal/slot mechanism is the Qt way for event driven classes to post data to listenner classes and for those listenner classes to receive the data.

      I light my way forward with the fires of all the bridges I've burned behind me.

      ahsan737A 1 Reply Last reply
      4
      • Kent-DorfmanK Kent-Dorfman

        I have a suspicion that your question is deeper than simply sharing data between classes, but that you don't know how to properly ask it.

        The signal/slot mechanism is the Qt way for event driven classes to post data to listenner classes and for those listenner classes to receive the data.

        ahsan737A Offline
        ahsan737A Offline
        ahsan737
        wrote on last edited by
        #3

        @kent-dorfman Since I am a beginner so I am not even familiar with most of the terms. Thank you for your kind suggestion. How can I implement Signal/Slot in this case?

        jsulmJ 1 Reply Last reply
        0
        • ahsan737A ahsan737

          @kent-dorfman Since I am a beginner so I am not even familiar with most of the terms. Thank you for your kind suggestion. How can I implement Signal/Slot in this case?

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

          @ahsan737 Start here: https://doc.qt.io/qt-5/signalsandslots.html You should really learn this as signals/slots are core functionality in Qt.
          In short: in your first class you define a signal with a parameter for the data you want to send to the second class. In the second class you define a slot with same parameter. Then you create instances of both classes and connect signal and slot. In the first class you emit the signal each time new data is available and pass the data to signal as parameter.

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

          1 Reply Last reply
          4

          • Login

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