原创 qt4.5.2 designer 设计ui界面并且编译运行

2010-2-7 22:13 3910 3 3 分类: MCU/ 嵌入式
1.首先设置QT库环境
export LD_LIBRARY_PATH=/root/qt-x11-opensource-src-4.5.2/lib:$LD_LIBRARY_PATH
cd /root/qt-x11-opensource-src-4.5.2/bin
./designer &
2.设计一个ui界面,保存到/root目录,命名为hu.ui
3.设置qmake环境

    export QTEDIR=/usr/local/Trolltech/QtEmbedded-4.5.2-x86/
    export PATH=/usr/local/Trolltech/QtEmbedded-4.5.2-x86/bin/:$PATH
    export LD_LIBRARY_PATH=/usr/local/Trolltech/QtEmbedded-4.5.2-x86/lib/:$LD_LIBRARY_PATH
4.将hu.ui导出头文件, uic -o hu.ui hu.ui
#include <QtGui/QTimeEdit>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_MainWindow
{
public:
    QWidget *centralwidget;
    QPushButton *pushButton;
    QSlider *horizontalSlider;
    QTimeEdit *timeEdit;
    QMenuBar *menubar;
    QStatusBar *statusbar;

    void setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
        MainWindow->resize(800, 600);
        centralwidget = new QWidget(MainWindow);
        centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
        pushButton = new QPushButton(centralwidget);
        pushButton->setObjectName(QString::fromUtf8("pushButton"));
        pushButton->setGeometry(QRect(30, 40, 92, 28));
        horizontalSlider = new QSlider(centralwidget);
        horizontalSlider->setObjectName(QString::fromUtf8("horizontalSlider"));
        horizontalSlider->setGeometry(QRect(50, 100, 160, 17));
        horizontalSlider->setOrientation(Qt::Horizontal);
        timeEdit = new QTimeEdit(centralwidget);
        timeEdit->setObjectName(QString::fromUtf8("timeEdit"));
        timeEdit->setGeometry(QRect(70, 150, 118, 28));
        MainWindow->setCentralWidget(centralwidget);
        menubar = new QMenuBar(MainWindow);
        menubar->setObjectName(QString::fromUtf8("menubar"));
        menubar->setGeometry(QRect(0, 0, 800, 25));
        MainWindow->setMenuBar(menubar);
        statusbar = new QStatusBar(MainWindow);
        statusbar->setObjectName(QString::fromUtf8("statusbar"));
        MainWindow->setStatusBar(statusbar);

        retranslateUi(MainWindow);

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

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

};

namespace Ui {
    class MainWindow: public Ui_MainWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // HU_H
5.添加main.cpp文件如下
#include <qapplication.h>
#include <qpushbutton.h>
#include <QWidget>
#include "hu.h"
class Win : public QMainWindow, public Ui::MainWindow
{
 public:
      Win(QMainWindow *parent = 0):QMainWindow(parent)
      {setupUi(this);}
};

int main( int argc, char *argv[] )
{
    QApplication a(argc, argv);
    Win w;
    w.show();
    return a.exec();
   
}
6.然后生成.pro工程文件 和Makefile文件
qmake -project
qmake hu.pro
7.最后make
将生成的执行文件通过QVFB测试

文章评论0条评论)

登录后参与讨论
我要评论
0
3
关闭 站长推荐上一条 /2 下一条