Qt学习(1)
(1)Qt跨平台
(2)Qt的路径不能有中文
(3)Qt的关键是信号与槽
(4)Qt项目不能以中文拼音、变量名、函数名命名,同一个项目命名应该同一形式(下划线或者驼峰)
(5)Qt常用头文件:
#include //文本编辑框控件类
eg://初始化对象
QLineEdit *NameLineEdit;//.h
NameLineEdit=new QLineEdit;//.cpp
#include //QDateTime类提供了日期和时间功能的类
eg://获取当前系统时间
QLabel=new *TimeLabel;//.h
TimeLabel=new QLabel(tr(QDateTime::currentDateTime().toString(“yyyy.MM.dd hh:mm ddd”)));//.cpp
Expression Output
h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H the hour without a leading zero (0 to 23, even with AM/PM display)
HH the hour with a leading zero (00 to 23, even with AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the second without a leading zero (0 to 59)
ss the second with a leading zero (00 to 59)
z the milliseconds without leading zeroes (0 to 999)
zzz the milliseconds with leading zeroes (000 to 999)
AP or A interpret as an AM/PM time. AP must be either “AM” or “PM”.
ap or a nterpret as an AM/PM time. ap must be either “am” or “pm”.
#include //限制文本框输入类
eg:
QRegExp nx("1\w{5,17}$");//密码必须以字母开头,长度在6~18之间,只能包含字符、数字和下划线。
#include //按钮控件类
eg:
QPushButton *OkBtn;//.h
QPushButton *CancelBtn;
OkBtn=new QPushButton(tr(“确定”));//.cpp
CancelBtn=new QPushButton(tr(“取消”));
#include //下拉选项框控制类
eg:
QComboBox *SexComboBox;//.h
SexComboBox=new QComboBox;//.cpp
SexComboBox->addItem(tr(“女”));
SexComboBox->addItem(tr(“男”));
#include //标签控件类
eg:
QLabel *NameLabel;//.h
NameLabel=new QLabel(tr(“姓名:”));//.cpp
#include //布局设置类
eg:
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
#include //网格布局设置类
eg:
QGridLayout *setLayout;
setLayout=new QGridLayout(this);
setLayout->setColumnStretch(0,3);
setLayout->setMargin(15);
setLayout->setSpacing(10);
setLayout->setSizeConstraint(QLayout::SetFixedSize);
#include //工具盒类
#include //工具盒按钮类
eg:
class Drawer : public QToolBox
{
Q_OBJECT
public:
Drawer();
private:
QToolButton *toolBtn1;
QToolButton *toolBtn2;
QToolButton *toolBtn3;
#include //工具盒分组类
eg:
QGroupBox *groupBox1=new QGroupBox;
QVBoxLayout *layout1=new QVBoxLayout(groupBox1);
#include //工具盒垂直布局类
#include //工具盒水平布局类
#include //对话框类
eg:
class login : public QDialog
{
Q_OBJECT
}
#include //选择控件类
eg:
QRadioButton *button = new QRadioButton(“Search from the &cursor”, this);
#include //按钮组合类
eg:
QButtonGroup *penGroup//.h
penGroup = new QButtonGroup(this);//.cpp
penGroup->addButton(powerOnBtn);
#include
#include
#include
#include
#include
eg:
-
a-zA-Z ↩︎