Är det smart att kasta om QWidget till en Window-klass i QT C++?
Jag har en form som heter DatabaseMeasurementTypeWindow. Den ärver klassen QWidget
#include <QWidget>
#include <QPushButton>
#include <QVariant>
#define DATA_TYPE_ID "ID"
#define DATA_TYPE_MEASUREMENT_ID "Measurement ID"
#define DATA_TYPE_MEASUREMENT_COMMENT "Measurement comment"
#define DATA_TYPE_DATE_TIME "Date time"
#define DATA_TYPE_MEASUREMENT_VALUE "Measurement value"
namespace Ui {
class DatabaseMeasurementTypeWindow;
}
class DatabaseMeasurementTypeWindow : public QWidget
{
Q_OBJECT
public:
explicit DatabaseMeasurementTypeWindow(QWidget *parent = nullptr, QPushButton *cellButton = nullptr);
~DatabaseMeasurementTypeWindow();
public slots:
void slotSetCellValue(QVariant cellValue);
private slots:
void on_dataTypeComboBox_currentTextChanged(const QString &arg1);
private:
Ui::DatabaseMeasurementTypeWindow *ui;
/* Other objects */
QPushButton *cellButton;
QVariant cellValue;
/* Other functions */
void closeEvent(QCloseEvent *event);
};
#endif // DATABASEMEASUREMENTTYPEWINDOW_H
Det jag vill göra är att jag vill komma åt ui komponenterna från DatabaseMeasurementTypeWindow igenom denna kod
DatabaseMeasurementTypeWindow* cellForm = dynamic_cast<DatabaseMeasurementTypeWindow*>(ui->templateTableWidget->cellWidget(row, column));
Där varje cellForm har satt sig in i
QPushButton* cellButton = new QPushButton("Empty");
DatabaseMeasurementTypeWindow* cellForm = new DatabaseMeasurementTypeWindow(nullptr, cellButton);
ui->templateTableWidget->setCellWidget(x, y, cellButton);
Där ui->templateTableWidget är en TableWidget och befinner sig INTE i DatabaseMeasurementTypeWindow
Fråga
Det enda sättet för mig att komma åt en cellWidget från ui->templateTableWidget är att anropa
ui->templateTableWidget->cellWidget(row, column);
Men denna kod retunerar tillbaka klassen QWidget*.
Är det då smart att använda sig av
dynamic_cast<DatabaseMeasurementTypeWindow*>
För att kasta om QWidget* till DatabaseMeasurementTypeWindow* ?