分享

[QFileDialog]关于选择文件对话框中的几个信号的说明

 星星的约会325 2012-03-28


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  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多