QT三种窗口、调试终端信息打印、新建菜单、设置窗口标题名称、界面初始化、打开文件对话框、保存文件对话框
生活随笔
收集整理的這篇文章主要介紹了
QT三种窗口、调试终端信息打印、新建菜单、设置窗口标题名称、界面初始化、打开文件对话框、保存文件对话框
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
三種窗口
QMainWindow:主窗口程序(創建菜單)
QWidget:部件窗口
QDialog:對話框窗口
?
調試終端信息打印
#include <QtDebug>qDebug << "not modifed";?
新建菜單
快捷鍵(Alt+F):文件(&F)
#include <QtDebug>private slots:void newFileSlot();QObject::connect(ui->newAction, SIGNAL(triggred(), this, SLOT(newFileSlot()))void MainWindow::newFileSlot() {//如果當前文檔內容已經改變了if(ui->textEdit->document()->isModified()){qDebug() << "current file modifed";}else{qDebug << "not modifed";} }?
設置窗口標題名稱
this->setWindowTitle("1111111111");?
界面初始化
Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui->setupUi(this);this->setWindowTitle("1111111111"); //初始化位置QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(calSlot())); }?
打開文件對話框,讀取文件信息
#include <QFile> #include <QFileDialog> #include <QDir>void MainWindow::OpenFileSlot() {//獲取程序當前路徑QString str = QFileDialog::getOpenFileName(this, "Open File", QDir::currentPath());if (str.isEmpty()){QMessageBoxreturn;}QFile *file = new QFile;file->setFileName(fileName);bool ok = file->open(QIODevice::ReadOnly);if (ok){QTextStream in(file);//in.readAll(); //read allui->textEdit->setText(in.readAll());file->close();delete file;}else{return;} }?
保存文件對話框
void MainWindow::saveFileSlot() {QString fileName = QFileDialog::getSaveFileName(this, "Save File", QDir::currentPath());if (fileName.isE,pty()){QMessageBOX::information()return;}QFile * file = new QFile;file->setFileName(fileName);bool ok = file->open(QIODevice::WriteOnly);if(ok){QTextStream out(file);out << ui->textEdit->toPlainText(); //取出textEdit純文本 file.close();delete file;}else{return;} }?
總結
以上是生活随笔為你收集整理的QT三种窗口、调试终端信息打印、新建菜单、设置窗口标题名称、界面初始化、打开文件对话框、保存文件对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 22. PE结构-PE详解之输入表(导入
- 下一篇: 操作系统实践(一)