zoukankan      html  css  js  c++  java
  • QFileDialog关于选择文件对话框中的几个信号的说明(currentChanged,directoryEntered,fileSelected,filterSelected)

    QFileDialog关于选择文件对话框中的几个信号 实例:

    openFile::openFile(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::openFile)
    {
    ui->setupUi(this);
    fDialog = new QFileDialog(this);
    fDialog->setFileMode(QFileDialog::Directory);
    connect(fDialog,SIGNAL(currentChanged ( const QString & )),this,SLOT(cc(const QString & )));
    connect(fDialog,SIGNAL(directoryEntered ( const QString &)),this,SLOT(de(const QString & )));
    connect(fDialog,SIGNAL(fileSelected ( const QString & )),this,SLOT(fs(const QString & )));
    connect(fDialog,SIGNAL(filesSelected ( const QStringList & )),this,SLOT(fss(const QStringList & )));
    connect(fDialog,SIGNAL(filterSelected ( const QString &)),this,SLOT(frs(const QString & )));

    fDialog->hide();
    }

    openFile::~openFile()
    {
    delete ui;
    }

    void openFile::on_pushButton_clicked()
    {
    fDialog->show();

    }

    void openFile::cc(const QString & path)
    {
    //在窗口中选择文件夹会出发该信号
    qDebug() <<"cc";
    qDebug() << path;
    }
    void openFile::de(const QString & directory){
    //选择文件夹进入时时触发 setFileMode(QFileDialog::Directory);
    qDebug() <<"de";
    qDebug() << directory;
    }
    void openFile::fs(const QString & file){
    //选中文件点击open后会出发该信号 至在打开单一文件时出发
    qDebug() <<"fs";
    qDebug() << file;
    }

    void openFile::fss(const QStringList & selected){
    //选中文件点击open后会出发该信号 选择单个或多个文件时出发 setFileMode(QFileDialog::ExistingFiles);
    qDebug() <<"fss";
    qDebug() << selected;
    }

    void openFile::frs(const QString & filter){
    qDebug() <<"frs";
    qDebug() << filter;
    }
    如果要保存一个文件
    需要设置这两个属性
    fDialog->setFileMode(QFileDialog::AnyFile);
    fDialog->setAcceptMode(QFileDialog::AcceptSave); //open按钮就会显示为save


    void frmMain::on_pushButton_file_clicked()
    {

    QString file = QFileDialog::getOpenFileName(this, tr("Open File"),"",tr("(*.bin)"));
    qDebug() << file;

    ……
    这种方式的文件选择对话框是和系统保持一致的。


    保存文件:

    QString filePathName = QFileDialog::getSaveFileName(this,tr("Open Config"),defaultFileName,tr("*"));

    if (!filePathName.isNull())
    {
    }
    else
    {

    ---------------------
    作者:阳光柠檬_
    来源:CSDN
    原文:https://blog.csdn.net/liukang325/article/details/13768589
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    自学Zabbix8.1 Regular expressions 正则表达式
    自学Zabbix7.1 IT services
    自学Zabbix6.1 Event acknowledgment 事件确认
    自学Zabbix5.1 zabbix maintenance维护周期
    自学Zabbix4.3 zabbix实战监控Web网站性能
    自学Zabbix4.2.1 Application介绍
    自学Zabbix4.2 web监控项创建+item详解
    自学Zabbix4.1 zabbix监控web服务器访问性能
    自学Zabbix3.11-宏Macros
    自学Zabbix3.10.2-事件通知Notifications upon events-Actions报警配置
  • 原文地址:https://www.cnblogs.com/findumars/p/9818464.html
Copyright © 2011-2022 走看看