Policies/API to Avoid: Difference between revisions

From KDE TechBase
m (Text replace - "<code cppqt>" to "<syntaxhighlight lang="cpp-qt">")
(Replaced content with "{{Moved To Community}}")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
There are classes and functions that should be avoided in KDE applications, but KDE has no direct control over them (for example, they are part of Qt).
{{Moved To Community}}
 
== API that has KDE replacements ==
 
=== Qt classes that have their KDE versions ===
KDE applications should not use Qt classes that have their KDE replacements. Examples include QFileDialog, QDialog, QMainWindow. KDE versions of these classes provide better integration with KDE.
 
=== QSystemTrayIcon::showMessage() ===
 
Use KNotification for better KDE integration.
 
=== QHttp ===
 
QHttp does not respect desktop settings such as the user's proxy settings or resource restrictions. Always use KIO to access network resources.
 
== API that is considered broken ==
 
=== QWidget::showFullScreen/Maximized/Minimized/Normal() ===
 
Try to avoid calls to QWidget::showFullScreen(), QWidget::showMaximized(), QWidget::showMinimized() and QWidget::showNormal(), use them only if you understand what they do and you really want that. These calls do not only change the relevant window state as most people expect, but they also have other effects. For example, showFullScreen() among other things also removes the maximized state (see [http://bugs.kde.org/show_bug.cgi?id=157941 bug #157941]), the same way showNormal() is not an inverse call to showFullScreen().
 
Either use QWidget::setWindowState() in the following way
<syntaxhighlight lang="cpp-qt">
widget->setWindowState(widget->windowState() | Qt::WindowFullScreen); // set
widget->setWindowState(widget->windowState() & ~Qt::WindowFullScreen); // reset
</code>
or use KDE API - KToggleFullScreenAction has setFullScreen() helper function, and KWindowSystem has calls for changing window state.
 
== Further Links ==
For further programming tips, please read the article about [[Development/Tutorials/Common_Programming_Mistakes|common programming mistakes]].

Latest revision as of 18:27, 10 March 2016

This page is now on the community wiki.