Sunday, 15 April 2012

c++ - QDir::setCurrent vs QFileInfo:: -


I came to Qt in an anomaly (v4.8.4), when a pre-existing QDir object indicates a low Example:

  QString path1 ("F: /"); // path must exist ... the Qstrung path 2 ("F: / some / valid / path / for / you"); // path must exist ... // set default ... QFileInfo fi1 (path1); Quadir D (Phi 1. BSOltdDeir ()); // Case 1 ... if (! D. Cirant (Path 2)) {qDebug () & lt; & Lt; Caststring ("path (% 1) can not be determined"). Arg (path2) .toAscii (). Data (); Return -1; } QDebug () & lt; & Lt; "case 1:"; QDebug () & lt; & Lt; Caststring ("Path 2:% 1"). Arg (path2) .toAscii (). Data (); QDebug () & lt; & Lt; Qestring ("D:% 1"). Arg (d.absolutePath ()). ToAscii (). Data (); // End of Case 1 ... // Case 2 ... QFileInfo fi2 (path2); D = fi2.absoluteDir (); QDebug () & lt; & Lt; "Case 2:"; QDebug () & lt; & Lt; Caststring ("Path 2:% 1"). Arg (path2) .toAscii (). Data (); QDebug () & lt; & Lt; Qestring ("D:% 1"). Arg (d.absolutePath ()). ToAscii (). Data (); // End of Case 2 ...   

Even if call d.setCurrent (path2) calls true The new path is not set in the QDir object OTOH, after assigning the new path 1 to the QFileInfo object, and calling absoluteDir () on that object returns an updated QDir object.

You can then return the object directly to an already existing QDir object (through the override assignment operator), and the path in the QDir object will be updated correctly.

Why does no 1 work?

QDir :: setCurrent is a static function which is the current path of the application Sets. This does not modify any QDir example

assign you a new path (or QString directly to QDir To use QDir :: setpath = operator, since the conversion is implied).

No comments:

Post a Comment