The first option does provide better performance than using the signal/slot mechanism, but it also has the drawback that there is a tight coupling between MainWindow
and DataManager
. Both know each other, so they can't really be used separately.
That alone should already be a reason to refactor the code.
That said, as a third option you could let MainWindow
have the slot that received the signal from DataWorker
and let DataManager
be a helper class that just converts the data into a usable format for MainWindow
.
class MainWindow
{
private:
DataManager* dm;
public:
MainWindow() : dm(new DataManager()) { }
displayData(QString processedData);
private slots;
eventNewData()
{
// get the data
QString processedData = dm->preprocessData(data);
displayData(processedData);
// release data
}
};
class DataManager
{
public:
QString preprocessData(...);
};