QT入门

1.绑定事件,消息槽什么的
QObject::connect(&hello,SIGNAL(clicked()),&a,SLOT(quit()));
↑ ↑ ↑ ↑
控件 事件 接收者 接收者事件
可以使用F4进入槽编辑模式,选中控件后按ctrl拖拽到接收者,然后选择对应事件

2.图形界面绑定槽
右键控件,选择转到槽

3.模式窗体
this->setWindowModality(Qt::ApplicationModal);

4.打开文件
QString filename = QFileDialog::getOpenFileName(this,"Open Document",QDir::currentPath(),"All files(*.*)");

5.读取文件
QFilefile(filename);
if(!file.open(QIODevice::ReadOnly|QIODevice::Text)){
this->fileinfo="Can't open the file!";
}
while(!file.atEnd()){
QByteArrayline=file.readLine();
this->fileinfo+=line;
}
file.close();

6.横向布局与纵向布局
QHBoxLayout、QVBoxLayout
Ctrl+H Ctrl+L

7.QWebView不显示
"无法添加外部的xxxxx..."
在pro中添加QT += widgets webkit webkitwidgets

如果不显示网站,可尝试
http://blog.csdn.net/sgnh123456/article/details/8020683





原文地址:https://www.cnblogs.com/punkrocker/p/2950981.html