在Qt上使用UIC(C ++) [英] Using UIC on Qt (c++)

查看:441
本文介绍了在Qt上使用UIC(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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆