Important: Please read the Qt Code of Conduct -

How to control a widget which created by UI Designer ?

  • Dear Sirs,

    I put a tabWidget on the MainWindow, this tabWidget is drag and drop from UI designer, so there is no "QTabWidget *tabWidget" declaration on the header file.

    Now I want to add a new tab by code, such as "tabWidget->addTab(button1, "Tab1");".
    Obviously there is no such widget for me to use, because this object is not declared before.

    What should I do ?

    Is there any way to tell compiler to find this object from UI designer ?

    Appreciate for any comments,

  • Hi Hiloshi,

    in your constructor you can use :

    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        ui->tabWidget->addTab(button1, "Tab1");"

    The ui pointer is your gate to everything you defined in Qt Designer.


  • Dear @Eddy ,

    Yes, I should able do that. Thank you very much.

    Best Regarts,

Log in to reply