1在Creator QT中以存文本的格式创建HelloWorld
首先,新建新项目,选择“其他项目”–“Empty qmake Project” ,然后根据提示完成项目创建。
其次,双击.pro文件,在里面添加
greaterThan(QT_MAJOR_VERSION,4):QT+=widgets
接着,右键项目名称那,选择“AddNew”--“C++ Source File”,命名为“main.cpp”,再在main.cpp内添加
#include <QApplication>
#include <QDialog>
#include <QLabel>
int main(int * argc,char * argv[])
{
QApplication a(argc,argv);
QDialog w;
QLabel label(&w);
label.setText("Hello World");
w.show();
return a.exec();
}
此时显示的弹窗非常小,我们可以用代码进行设置,通过添加w.resize(400,600)进行大小设置。如果需要将Label位置进行设置,则添加label.move(200,100);
#include <QApplication>
#include <QDialog>
#include <QLabel>
int main(int argc,char * argv[])
{
QApplication a(argc,argv);
QDialog w;
QLabel label(&w);
label.setText("Hello QT");
w.resize(300,400);
label.move(200,100);
w.show();
return a.exec();
}