我有點困惑,想澄清這一點。爲什麼這個工作和如何?非靜態Qt對象
//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");
我主要關心的是爲什麼最後一個examaple [QDir()。rmdir]工作? 我已經注意到這個Qt類的數量。這是一個匿名對象嗎?如果是的話,這對於對象清理來說意味着什麼?這種形式可以安全使用嗎?
你的意思是`QDir :: rmdir(「Y:/ dir1/dir2/dir3」)?它仍然不起作用,因爲`QDir :: rmdir`不是靜態的,但`QDir():: rmdir`中的額外括號沒有意義。 – aschepler 2011-02-14 16:35:32