Using UIC on Qt (c++)

感情迁移 提交于 2019-12-02 03:22:14

问题


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


回答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);
  }
};


来源:https://stackoverflow.com/questions/39901747/using-uic-on-qt-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!