Important: Please read the Qt Code of Conduct -

Variable value sharing between Classes

  • 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?

  • 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.

  • @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?

  • Qt Champions 2019

    @ahsan737 Start here: 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.

Log in to reply