QT beginner QFileDialog

news/发布时间2024/5/18 12:19:05
QFile
QTextStream
QMessageBox
QFileDialog
应用示例
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QTextStream> #include <QMessageBox> #include <QFileDialog> MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) {ui->setupUi(this); }MainWindow::~MainWindow() {delete ui; }mainwindow.cpp void MainWindow::on_pushButton_2_clicked() {//QFile file("./mytest1.txt");QFile file("/mnt/hgfs/temp/QFileDemo/mytext.txt");if(!file.open(QFile::WriteOnly | QFile::Text)){QMessageBox::warning(this,"title","file not open");}QTextStream out(&file);QString text= ui->plainTextEdit->toPlainText();out<<text;file.flush();file.close(); }void MainWindow::on_pushButton_clicked() { QString filter="All File(*.*);;Text File(*.txt);;xml File(*.xml)";QString file_name=QFileDialog::getOpenFileName(this,"open a file","/",filter);QFile file(file_name);//QFile file("/mnt/hgfs/temp/QFileDemo/mytext.txt");if(!file.open(QFile::ReadOnly | QFile::Text)){QMessageBox::warning(this,"title","file not open");}QTextStream in(&file);QString text=in.readAll();ui->plainTextEdit->setPlainText(text);file.close(); }
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_pushButton_2_clicked();void on_pushButton_clicked();private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ulsteruni.cn/article/63477317.html

如若内容造成侵权/违法违规/事实不符,请联系编程大学网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

IEC104 从站/服务端模拟器 调试工具推荐

在开发调试过程中,一款合适的从站模拟器可以大大提高效率。下面推荐一款IEC104 从站/服务端模拟器。目录IEC104 从站/服务端模拟器 调试工具推荐主要功能软件截图 IEC104 从站/服务端模拟器 调试工具推荐 下载地址:http://www.redisant.cn/iec104server IEC 60870-5-104,通常…

MibBrowser工具测试服务器告警上报

在工具栏【tools】---》【Trap Receiver】选择与服务器直连网卡的IP地址及对应的端口号(确保自己的电脑可以正常和服务器通信)在BMC Trap位置配置自己电脑的IP地址,用于接收上报的告警信息点击【测试】查看已经正常收到服务器测试上报信息了。你也可以尝试拔盘和拔电源看看是…

Windows Server 2016 中文版、英文版下载 (updated Apr 2024)

Windows Server 2016 中文版、英文版下载 (updated Apr 2024)Windows Server 2016 中文版、英文版下载 (updated Apr 2024) Windows Server 2016 Version 1607,2024 年 4 月更新 请访问原文链接:Windows Server 2016 中文版、英文版下载 (updated Apr 2024),查看最新版。原创…

收集:本地运行Llama3

本地运行Llama3新方法#国外有网友火速分享了在本地(Windows、Linux、Mac)一键运行 Llama 3 的新方法~废话不多说,先看效果。【图1】在视频1倍速播放中,他用 OpenWebUI 在自己的 Macbook Pro M1 Max 64G 上成功运行了 Llama 3 。而且还添加了侧边栏展开收起。【图2】以上效果…

TPU-MLIR快速入门

12.1 TPU-MLIR快速入门 12.1.1 TPU-MLIR简介 后文假定用户已经处于docker里面的/workspace目录。 1.编译ONNX模型 以 yolov5s.onnx 为例, 介绍如何编译迁移一个onnx模型至BM1684X TPU平台运行。 该模型来自yolov5的官网: https://github.com/ultralytics/yolov5/releases/downl…

centos7安装python3.12.3(最新)

一.安装环境: Linux系统:centos7,可以正常访问互联网。 python版本:3.12.3,建议网工直接就是安装python3的最新版本,毕竟python2和我们网工更不相关了。 环境最基本的就这些了 二.安装步骤 1.安装python3: 不多说,直接上安装过程~ #只是将python3.12.3的安装包下载到 /…