Qfiledialog Use the dialog box to select a local file

Source: Internet
Author: User
 Qfiledialog *filedialog = new Qfiledialog (this);//Create a Qfiledialog object in which the parameters in the constructor can be added. 
    Filedialog->setwindowtitle (TR ("Save As"));//Set the title Filedialog->setacceptmode of the File Save dialog box (qfiledialog::acceptsave //The Setup File dialog box displays any files, whether folders or files, when it pops up in the Save Mode Filedialog->setfilemode (Qfiledialog::anyfile);//Settings File dialog box filedialog-

                                                                      >setviewmode (qfiledialog::D etail);//file in a detailed form display, display file name, size, date of creation and other information; There is another form of qfiledialog::list, which simply displays the file's filename as a list filedialog->setgeometry (10,30,300,200);//Set File Dialog Display position filedialog->setdirectory ("."); /sets the location of the initial opening when the file dialog box opens Filedialog->setfilter (tr ("Image Files (*.jpg *.png)"));/Set File type filter if (filedialog->exec () = = qdialog::accepted) {//Note the use of qfiledialog::accepted or qdialog::accepted, not qfiledialog::accept QString path = Filedi Alog->selectedfiles () [0];//Gets the user-selected filename filepath=listwidget_file->item (Listwidget_file->currentrow ())- >text ()//This is a picture that gets clicked in Listwidget, gets the name of this picture filepath=qstring ("/media/sd/pictures") +filepath;//connects the path and file nameGet up QImage IIM (FilePath);//Create a Picture object, save source picture qpainter painter (&iim);//Set Painting device Qfile file (path);//Create
        A file object that stores the user-selected file if (!file.open (Qiodevice::readwrite)) {Opens the user-selected file in a read-only manner, and returns return if it fails; }
Write a file in a streaming manner
1         qbytearray BA;
2         qbuffer buffer (&BA);
3         Buffer.open (qiodevice::writeonly);
4         Iim.save (&buffer, "JPG");//stream the picture to the file cache stream
5         file.write (BA);//write the picture in the stream to the file object

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.