• 13049阅读
  • 8回复

如何将ui文件转成.h .cpp文件 [复制链接]

上一主题 下一主题
离线hanb99
 

只看楼主 正序阅读 楼主  发表于: 2006-10-28
ubuntu6.06+qt4.1.2
这个是我的编译环境。
我用designer-qt4做了一个界面后生成一个button.ui文件,但我怎么也不能将它转成.cpp文件更不用说编译成可执行文件了。
我只能生成.h文件:
$ uic -o form1.h button.ui   //这步没有问题生成了form1.h文件

$ uic -i form1.h -o form1.cpp button.ui     //这步就不行了,它只是显示了一下下面的东东
whf@wanghf:~/src/test/ui$ uic -i form1.h -o form1.cpp button.ui
Qt user interface compiler 4.1.2.
Usage: uic [OPTION]... <UIFILE>

-h, -help           display this help and exit
-v, -version         display version
-d, -dependencies       display the dependencies
-o <file>           place the output into <file>
-tr <func>           use func() for i18n
-p, -no-protection     disable header protection

上面的命令是在网上找的,那里错了呢??具体要怎么做呢?
另外我想问一下是不是生成.h .cpp文件后就可以用
qmake -project
qmake
make
命令生成可执行文件了。
[ 此贴被XChinux在2006-11-16 23:15重新编辑 ]
离线hanb99

只看该作者 8楼 发表于: 2006-11-10
这个问题解决了,和大家共享一下,
uic -i button.h -o button.cpp button.ui
在QT4中好象没有-i 这个参数,所以无法自己生成.cpp文件,要手写。

#include <QApplication>
#include <QWidget>
#include "button.h"

class Win : public QWidget, public Ui::Form
{
  public:
    Win(QWidget *parent = 0):QWidget(parent)
  {setupUi(this);}
};

int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  Win w;
  w.show();
  return app.exec();
}

这段代码和 1 楼的代码放到一个文件夹中,就可以用 qmake -project   qmake   make 编译了,
离线wangowen

只看该作者 7楼 发表于: 2006-10-30
一般来说我们把声明放在.h文件中,定义在.cpp文件中。
用uic生成的.h文件函数已经定义好了,并不一定要.cpp文件。
离线zorachung
只看该作者 6楼 发表于: 2006-10-30
我也有同样的疑问,就是.ui的相应的.cpp是如何生成的,我用的是windows 下vc6编程环境。急需解答!!
离线hanb99

只看该作者 5楼 发表于: 2006-10-30
引用第3楼漏斗の水风2006-10-29 21:00发表的“”:
其实不用转化也能用qmake -project阿
以前有一个转化的网上的脚本你看看
http://oaunix.hlhs.hlc.edu.tw/bcc/study-area/-http---www.study-area.org-tips-qd-qt.html
这个跟你那个是一样的
.......


这个帖子我在本站看过一个和这个差不多的,我也照着做过,不可用,提示
whf@wanghf:~/src/test/ui$ uic -o button.h button.ui           //这步是成功的
whf@wanghf:~/src/test/ui$ uic -i button.h -o button.cpp button.ui //这步就这样了
Qt user interface compiler 4.1.2.
Usage: uic [OPTION]... <UIFILE>

-h, -help           display this help and exit
-v, -version         display version
-d, -dependencies       display the dependencies
-o <file>           place the output into <file>
-tr <func>           use func() for i18n
-p, -no-protection     disable header protection

我看那个贴子的例子好象是QT4以前的版本,而我用的是QT4.1.2,是因为这个吗??
只看该作者 4楼 发表于: 2006-10-29
“$<”和“$@”是Makefile里的自动推导符
$<为第一个依赖文件
$@是目标文件

  ui_%.h: %.ui
    uic $< -o $@
即为uic %.ui -o ui_%
只看该作者 3楼 发表于: 2006-10-29
其实不用转化也能用qmake -project阿

以前有一个转化的网上的脚本你看看
http://oaunix.hlhs.hlc.edu.tw/bcc/study-area/-http---www.study-area.org-tips-qd-qt.html
这个跟你那个是一样的
这个脚本以前我用过可以的
离线hanb99

只看该作者 2楼 发表于: 2006-10-28
Here are useful makefile rules if you only use GNU make:
  ui_%.h: %.ui
        uic $< -o $@

If you want to write portably, you can use individual rules of the following form:
  ui_foo.h: foo.ui
        uic $< -o $@

这是
$ man uic  
中的内容,它是什么意思?“$<”和“$@”代表什么?晕了
离线hanb99

只看该作者 1楼 发表于: 2006-10-28
#ifndef FORM1_H
#define FORM1_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>

class Ui_Form
{
public:
  QPushButton *pushButton;

  void setupUi(QWidget *Form)
  {
  Form->setObjectName(QString::fromUtf8("Form"));
  Form->resize(QSize(400, 300).expandedTo(Form->minimumSizeHint()));
  pushButton = new QPushButton(Form);
  pushButton->setObjectName(QString::fromUtf8("pushButton"));
  pushButton->setGeometry(QRect(150, 190, 87, 30));
  retranslateUi(Form);
  QObject::connect(pushButton, SIGNAL(clicked()), Form, SLOT(close()));

  QMetaObject::connectSlotsByName(Form);
  } // setupUi

  void retranslateUi(QWidget *Form)
  {
  Form->setWindowTitle(QApplication::translate("Form", "Form", 0, QApplication::UnicodeUTF8));
  pushButton->setText(QApplication::translate("Form", "PushButton", 0, QApplication::UnicodeUTF8));
  Q_UNUSED(Form);
  } // retranslateUi

};

namespace Ui {
  class Form: public Ui_Form {};
} // namespace Ui

#endif // FORM1_H
+++++++++++++++++++++++++++++++++
这个文件就是通过
$ uic -o form1.h button.ui
生成的,可是为什么会和平常看到的不一样呢(没有继承,没有构造函数)还是这条命令我写的有问题
快速回复
限100 字节
 
上一个 下一个