Please nominate your Qt Champions for 2021!

QT Designer - using .ui file tutorial bug?

  • section - The Direct Approach

    Ui::CalculatorForm ui; // this not works (calculatorform not memember of UI namespace)

    QWidget *w = new QWidget;
    Ui::Form ui; // intelisense give me Form and this works fine

    Some wrong setting in creator settings or obsolete docu?
    for Qt newbie (like me ) its little bit frustrating.
    thanks for answers

  • are you referring to this "example": ?
    if so, did you add

    #include "ui_calculatorform.h"

    at the top?

    even with that though, i was not able to make it work properly.
    providing a QWidget only allows a root widget element to be there so that the rest of the widgets can use it as parent and draw themselves.

    there is no way to provide functionality with user provided slots.
    what i did was to have my main.cpp as

    #include <QApplication>
    #include "calculatorform.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

     CalculatorForm *widget = new CalculatorForm;
     return app.exec();


    and in calculatorform.cpp

    #include <QtGui>
    #include "calculatorform.h"
    #include "ui_calculatorform.h"

    CalculatorForm::CalculatorForm(QWidget *parent)
    : QWidget(parent),
    ui(new Ui::CalculatorForm)

    CalculatorForm::~CalculatorForm(void) {
    delete ui;


  • thanks for answer.
    yes i refered that example.

    i found what was wrong. In Qt Designer the widgets property objectName has default value "Form". After change to "CalculatorForm" is all ok.
    exactly like in the example.


Log in to reply