Valentin Taranto
Valentin Taranto

Reputation: 21

Using UIC on Qt (c++)

I'm looking for using Qt Designer and generate the cpp source corresponding to the .ui files.

After some researches, i've found that the UIC can do it.

Here is an example.

But there is no explanation about where to use the command .. I've tried to put it on .pro file an on command line argument(on project parameters). My command : uic -i mainwindow.h -o fruit.cpp mainwindow.ui

Upvotes: 2

Views: 3968

Answers (1)

If you have foo.ui and want to generate the ui_foo.h file, you should add the foo.ui to the FORMS list in the .pro file:

FORM += foo.ui

If you want to use uic manually from the command line, you can do so as well:

/path/to/my/qt/bin/uic -i foo.h -o ui_foo.h

You then include the generated header to use the Ui::Foo class:

// foo.h
...
#include "ui_foo.h"

class Foo : public QWidget {
  Ui::Foo ui; // no need for it to be a pointer!
  ...
public:
  explicit Foo(QWidget * parent = nullptr) : QWidget{parent} {
    ui.setupUi(this);
  }
};

Upvotes: 4

Related Questions