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