在Qt上使用UIC(C ++) [英] Using UIC on Qt (c++)
问题描述
我正在寻找使用Qt Designer并生成与.ui文件相对应的cpp源。
I'm looking for using Qt Designer and generate the cpp source corresponding to the .ui files.
经过一些研究,我发现UIC可以
After some researches, i've found that the UIC can do it.
此处是一个示例。
但是没有解释在何处使用该命令..我试图将其放在.pro文件中行参数(关于项目参数)。
我的命令:
uic -i mainwindow.h -o fruit.cpp mainwindow.ui
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
推荐答案
如果您有 foo.ui
并想生成 ui_foo.h
文件,则您应该将 foo.ui
添加到 .pro $ c中的
FORMS
列表中$ c>文件:
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
如果要从命令行手动使用 uic
,也可以这样做:
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
然后包含生成的标头以使用 Ui :: Foo
类:
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);
}
};
这篇关于在Qt上使用UIC(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!