为什么这样做以及如何工作?非静态Qt对象

use*_*297 2 c++ qt static qt4

我有点困惑,想清除它.

//QDir()::rmdir is from Qt Creator auto complete.
//It does not work. 
//Says no such static function.I looked it up, turns out to be true.
//Fair enough...though I'm not sure why auto-complete suggested it.
bool success = QDir()::rmdir("Y:/dir1/dir2/dir3");   //Does not work.

//Now I could make a QDir object as such.
//I didn;t test this but I'm sure it would work fine.
//However it seems clumsy.
QDir d("Y:/");     //This seems like a waste.
d.rmdir("Y:/dir1/dir2/dir3");

//Lastly, the source of my confusion.  QDir().rmdir
//This works, but WHY?
//There is no empty constructor for QDir in Qt Documentation.
//http://doc.qt.nokia.com/4.7/qdir.html
//Yet this empty constructor version works.  Why?
bool success = QDir().rmdir("Y:/dir1/dir2/dir3");
Run Code Online (Sandbox Code Playgroud)

我主要担心的是为什么最后的examaple [QDir(..rmdir)有效?我在很多Qt课上都注意到了这一点.这是一个匿名对象,如果是这样,这对于对象清理意味着什么?这种形式是否安全使用?

Pai*_*ng1 6

其中一个QDir构造函数是:

QDir ( const QString & path = QString() )
Run Code Online (Sandbox Code Playgroud)

您的QDir().xxx代码正在调用此构造函数,然后使用默认值将QString()作为一个参数.

这样做是安全和正常的.