Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shouldn't think of two libraries connected via signal and slots, but of sets of classes/class instances, one group of backend-related classes and a group of UI-related classes. The UI classes use the backend classes (but never the other way around). That these two sets of classes are in different libraries is a implementation detail of deployment and mostly irrelevant for the application design on C++ level. The design concepts are the same even if all code is linked together in a single application.</p> <p>Having a single "common class" with a single signal <code>signalUpdateGUIStatus(QString)</code> is most probably wrong approach. There's no point in restricting the interface to a single class or even signal just because it's a separate library. Small interfaces are good - but unless your backend code sends only one very specific kind of update, "signalUpdateUIStatus(QString whatChangedEncodedAsString)" would be doing far too much via a single class/signal. signalUpdateGUIStatus also implies that the backend library knows that there is an UI. It shouldn't. It just provides information about the devices on the network - whether there's a UI displaying the information or some bot sending notifications via e-mail (or whatever) is none of its business.</p> <p>You could have a shared library with exported classes like LightSensorListener, TemperatureSensorListener, etc. (or just DeviceListener, depends) which could be QObjects emitting signals when a value changes, but also have any other Q_PROPERTYs, methods, etc. These classes would be instantiated in the application and then connected to the UI code.</p> <p>Just think of how you use Qt in your application. Your library would be yet another library whose classes you use to get data from the network. Just like you use QString, QWidget, QLineEdit etc. to create and interact with the UI, you would use the classes of your library to interface with the network:</p> <p>Let's say our library "foo" has a class TemperatureSensor:</p> <pre><code> //file TemperatureSensor.h /** * A temperature sensor on the network. * yaddayaddayadda */ class FOO_EXPORT TemperatureSensor { Q_OBJECT Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) Q_PROPERTY(bool available READ available NOTIFY availableChanged) Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged) public: /** * Creates a temperature sensor * * @param parent parent QObject */ explicit TemperatureSensor(QObject* parent=0); /** * Returns whether the device is currently available and delivering data */ bool available() const; /** * Returns the temperature reported by the sensor (In Celsius) */ qreal temperature() const; /** * Makes the device explode. Use with caution! * Don't give this to little developers/children. */ void blowUp(); //address(), setAddress() etc... Q_SIGNALS: /** * The availability of the sensor changed * * @param available whether the sensor is now available */ void availableChanged(bool available); void temperatureChanged(qreal); void addressChanged(const QString&amp;); }; </code></pre> <p>Then the application, you just create the instances and hook them up with your UI:</p> <pre><code> TemperatureSensor sensor; sensor.setAddress("/tempsensors/1234"); TemperaturWidget widget; widget.show(); //connect signals from sensor, or pass the whole sensor instance, etc. </code></pre> <p>For documentation, all public classes of the library (i.e. everything that's exported) should be documented. signal/slots are usually documented just like other "normal" methods.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload