Use of qfiledialog in the file dialog box in QT

Source: Internet
Author: User
Use of qfiledialog in the file dialog box in QT-[programming] Tag: c
Reproduced in: http://feizf.blogbus.com/logs/5112083.html

The materials are from the official QT documents. I have summarized some of the frequently used documents:

1. The simplest method is to call a static function to obtain the file in the dialog box:
Qstring file = qfiledialog: getopenfilename (
"/Home/foxman ",
"Images (*. PNG *. XPM *. jpg )",
This );
This code can be used to create a file fetch dialog box. After the selection, OK will return the file path to the file.

II. General file dialog box usage
Qfiledialog * FD = new qfiledialog (this, "file DLG", true );
If (FD-> exec () = qfiledialog: accepted) // OK
{
Qstring file = FD-> selectedfile ();
Qwarning (s );
}

1. Several setting options:

A. Set the display mode.
FD-> setviewmode (qfiledialog: Detail );
// Detail displays the detailed file date and size. The list is normal.

B. Set the filter.
FD-> setfilter ("Images (*. PNG *. XPM *. jpg )");
Below are multiple filters, which must be separated by; (two semicolons)
Qstring filters = "C file (*. C *. cpp *. H); PIC (*. PNG *. XPM )";
FD-> setfilters (filters );

C. Set what is returned in the dialog box
FD-> setmode (qfiledialog: existingfile );
Anyfile (generally used in the Save As dialog box)
Existingfile
Existingfiles contains 0 or more files (multiple files can be selected)
Directory
Directoryonly returns the directory (only the directory is selected when the file is selected)

2. Return Value:
A. Return the name of the selected file (folder ).
Qstring S = FD-> selectedfile ();
B. Select multiple files (you must set the existingfiles Mode)
Qstringlist slist = FD-> selectedfiles ();
For (qstringlist: iterator it = slist. Begin (); it! = Slist. End (); It ++) // iterator
Qwarning (* it );

Appendix: String list qstringlist usage

1. append, +,

  • Previous Article: Compile qgis1.0.2 in MS Visual Studio 2008
  • Next article: Random Functions rand () [C ++]
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.