MyMainWindow.h ==================== #ifndef DASHBOARD_HPP #define DASHBOARD_HPP #include namespace Ui { class Dashboard; } namespace MyNamespace { class MyMainWindow : public QMainWindow { Q_OBJECT public: explicit MyMainWindow(QWidget *parent = 0); ~MyMainWindow(); void simpleMethod(); private: Ui::MyMainWindow *ui; QComboBox *comboMy; }; } // END namespace MyNamespace #endif // DASHBOARD_HPP MyMainWindow.cpp ============================ #include "MyMainWindow.hpp" #include "ui_MyMainWindow.h" #include namespace MyNamespace { MyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MyMainWindow) { ui->setupUi(this); QComboBox *comboMy = new QComboBox; // 1 ************************************ // Doing this in constructor works comboMy->addItem("asdf"); } MyMainWindow::~MyMainWindow() { delete ui; } void MyMainWindow::simpleMethod() { // 2 *********************************** // Bu this does not this->comboMy->addItem("asdf"); } } // END namespace MyNamespace