QFileInfo and QDir

You can pass a file system path to the construction function of QFileInfo like:

QFileInfo("C:\\a\\b/c/d/e");

The string passed as the parameter of the constructor is not necessarily a real file or directory, just has the form of a file system path. From the QFileInfo, we can get a QDir object:

QDir dir=QFileInfo("C:\\a\\b/c/d/e").dir();

 

We can get the path of the QDir object using:

dir.path();

 

In the above example, the dir path is C:/a/b/c/d, regardless of whether e is a file or directory. The constructor of QFileInfo can also take a relative path as its parameter such as

QFileInfo(“a/b/c/d/e”).

Now there are some issues needed notice:

  • what is QFileInfo(“a”).dir().path()? It is ., which you may know is the current directory. But what is QFileInfo(“.”).dir().path()? It’s still ., not the parent folder of current directory.
  • What is QFileInfo(“C:/a”).dir().path()? It is C:/. Then what is QFileInfo(“C:/”).dir().path()? It is still C:/.
Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Comments are closed, but trackbacks and pingbacks are open.