Policies/API to Avoid: Difference between revisions
m (Removed extra blank line.) |
|||
(13 intermediate revisions by 6 users not shown) | |||
Line 4: | Line 4: | ||
=== Qt classes that have their KDE versions === | === Qt classes that have their KDE versions === | ||
==== When buliding with kdelibs4 ==== | |||
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. | 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. | ||
==== When building with Qt5 and KDE Frameworks ==== | |||
For frameworks, a lot of functionality from K classes has been merged into upstream Q classes. Use of QFileDialog, QDialog, and QMainWindow are ok and even encouraged, while other classes like KLineEdit and KComboBox are only required for utilizing features like completion See [https://community.kde.org/Frameworks/Porting_Notes#Application Frameworks Porting Notes] for more details. | |||
=== QNetworkAccessManager === | |||
By default QNetworkAccessManager does not follow redirects. | |||
This is problematic as it prevents compatiblity fallback of server moves. | |||
Use of QNetworkAccessManager '''MUST''' include the line | |||
<syntaxhighlight lang="cpp-qt"> | |||
networkAccessManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); | |||
</syntaxhighlight> | |||
=== QSystemTrayIcon::showMessage() === | === QSystemTrayIcon::showMessage() === | ||
Use KNotification for better KDE integration. | 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 == | == API that is considered broken == | ||
Line 17: | Line 35: | ||
Either use QWidget::setWindowState() in the following way | 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); // set | ||
widget->setWindowState(widget->windowState() & ~Qt::WindowFullScreen); // reset | widget->setWindowState(widget->windowState() & ~Qt::WindowFullScreen); // reset | ||
</ | </syntaxhighlight> | ||
or use KDE API - KToggleFullScreenAction has setFullScreen() helper function, and KWindowSystem has calls for changing window state. | or use KDE API - KToggleFullScreenAction has setFullScreen() helper function, and KWindowSystem has calls for changing window state. | ||
== Further Links == | == Further Links == | ||
For further programming tips, please read the article about [ | For further programming tips, please read the article about [https://techbase.kde.org/Development/Tutorials/Common_Programming_Mistakes common programming mistakes]. |
Latest revision as of 10:59, 21 February 2020
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).
API that has KDE replacements
Qt classes that have their KDE versions
When buliding with kdelibs4
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.
When building with Qt5 and KDE Frameworks
For frameworks, a lot of functionality from K classes has been merged into upstream Q classes. Use of QFileDialog, QDialog, and QMainWindow are ok and even encouraged, while other classes like KLineEdit and KComboBox are only required for utilizing features like completion See Frameworks Porting Notes for more details.
QNetworkAccessManager
By default QNetworkAccessManager does not follow redirects. This is problematic as it prevents compatiblity fallback of server moves.
Use of QNetworkAccessManager MUST include the line
networkAccessManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
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 bug #157941), the same way showNormal() is not an inverse call to showFullScreen().
Either use QWidget::setWindowState() in the following way
widget->setWindowState(widget->windowState() | Qt::WindowFullScreen); // set
widget->setWindowState(widget->windowState() & ~Qt::WindowFullScreen); // reset
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 common programming mistakes.