1.纯文本编辑方式:
编辑.cpp文件然后切换到该目录
运行
qmake -project 生成项目文件
qmake 生成Makefile文件
make 编译文件
2.用qt designer 编译图形界面
打开qt designer 编辑图形界面保存为 untitled.ui
运行
uic -o helloworld.h untitled.ui 来将.ui 文件转化成.h文件
然后你懂得......
/********************************************************************************
** Form generated from reading UI file 'untitled.ui'
**
** Created: Sun Jul 31 09:24:14 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Dialog
{
public:
QWidget *widget;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QLabel *label;
QLineEdit *lineEdit;
QHBoxLayout *horizontalLayout_2;
QLabel *label_2;
QLineEdit *lineEdit_2;
QHBoxLayout *horizontalLayout_3;
QPushButton *pushButton;
QPushButton *pushButton_2;
void setupUi(QDialog *Dialog)
{
if (Dialog->objectName().isEmpty())
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->resize(341, 252);
widget = new QWidget(Dialog);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(80, 120, 225, 101));
verticalLayout = new QVBoxLayout(widget);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
verticalLayout->setContentsMargins(0, 0, 0, 0);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
label = new QLabel(widget);
label->setObjectName(QString::fromUtf8("label"));
horizontalLayout->addWidget(label);
lineEdit = new QLineEdit(widget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
horizontalLayout->addWidget(lineEdit);
verticalLayout->addLayout(horizontalLayout);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
label_2 = new QLabel(widget);
label_2->setObjectName(QString::fromUtf8("label_2"));
horizontalLayout_2->addWidget(label_2);
lineEdit_2 = new QLineEdit(widget);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
horizontalLayout_2->addWidget(lineEdit_2);
verticalLayout->addLayout(horizontalLayout_2);
horizontalLayout_3 = new QHBoxLayout();
horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
pushButton = new QPushButton(widget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
horizontalLayout_3->addWidget(pushButton);
pushButton_2 = new QPushButton(widget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
horizontalLayout_3->addWidget(pushButton_2);
verticalLayout->addLayout(horizontalLayout_3);
retranslateUi(Dialog);
QMetaObject::connectSlotsByName(Dialog);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "Username", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("Dialog", "Passwd", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Dialog", "Ok", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("Dialog", "Callel", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // HELLOWORLD_H
//将注释部分去掉,就是简单的hello Qt程序....
#include<QApplication>
//#include<QPushButton>
#include"helloworld.h"
int main(int argc,char *argv[])//必须用完整形式
{
QApplication app(argc,argv);
///QPushButton hello("Hello Qt!");
QDialog dlg;
Ui_Dialog ui;
ui.setupUi(&dlg);
//hello.resize(100,30);
//hello.show();
dlg.show();
return app.exec();
}