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 ++]