开发者

function for getting instance of class VS calling class directly

http://doc.qt.io/qt-5/qdesktopwidget.html#obtaining-a-desktop-widget

The QApplication::desktop() function is used to get an instance of QDesktopWidget.

I don't understand why should you use QApplication::desktop(), when you can just directly call QDesktopWidget() class.

What is the difference between开发者_开发问答

desktop = QApplication.desktop() 

and

desktop = QDesktopWidget() 

They look like the same. But Windows(OS) throws warning on exit when using QDesktopWidget(). So there should be some difference.

How they differs?


They may look the same but are not. On the C++ side the static desktop() function is using a singleton pattern - there is only one desktop and it is represented by a static variable, which may (or may not) be created on request. QDesktopWidget() is a constructor, which is not accessible for the "outside world" to guarantee the uniqueness of the singleton.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜