Settings dialog, using information from its parent window My MainWindow popups a SettingsDialog. The setting dialog need to hide certain fields if the connected device is certain type.

void MainWindow::on_actionSettings_triggered()
{
    SettingsDialog * settings = new SettingsDialog(this);

    settings-&gt;exec();
}


Now in SettingsDialog:

SettingsDialog::SettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{
    ui-&gt;setupUi(this);

    QSettings settings;

    MainWindow * mainWindow = (MainWindow *) parent;

    if ( mainWindow-&gt;deviceType == DEVICE_TYPE_B )
    {
        ui-&gt;comboBoxIP-&gt;setVisible( false );
    }
}


It works fine but is it a good way to access the info which is present in the parent window? or should the parent window pass in the device type in the constructor so it only knows the device type and work with it?
If the SettingsDialog can only take a MainWindow as a parent in the constructor then declare it to be so:

SettingsDialog::SettingsDialog(MainWindow *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{


As for getting the type indeed passing it in explicitly is better.

void MainWindow::on_actionSettings_triggered()
{
    SettingsDialog * settings = new SettingsDialog(this, deviceType);

    settings-&gt;exec();
}


My MainWindow popups a SettingsDialog. The setting dialog need to hide certain fields if the connected device is certain type.

void MainWindow::on_actionSettings_triggered()
{
    SettingsDialog * settings = new SettingsDialog(this);

    settings-&gt;exec();
}


Now in SettingsDialog:

SettingsDialog::SettingsDialog(MainWindow *parent, DeviceType deviceType) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{
    ui-&gt;setupUi(this);

    QSettings settings;

    if (deviceType == DEVICE_TYPE_B )
    {
        ui-&gt;comboBoxIP-&gt;setVisible( false );
    }
}