Displaying only *.txt files in open file dialog



  • Hi All

    I have written the below code to filter only .txt files.
    @
    QString filename = QFileDialog::getOpenFileName(this,tr("Open Document"),QDir::currentPath(),tr("text files (*.txt);") );
    @
    But for above code it is not filtering and displaying *.txt files.

    If i write following code it is showing .txt files but also it will display all files when user selects All files option.
    @
    QString filename = QFileDialog::getOpenFileName(this,tr("Open Document"),QDir::currentPath(),tr("text files (
    .txt);;All files*.*)") );
    @
    So how to display only *.txt files?



  • Remove the semicolon:

    @QString filename = QFileDialog::getOpenFileName(this,tr("Open Document"),
    QDir::currentPath(),
    tr("text files (*.txt)"));@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.