Binary Compatibility Workarounds: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Adapt to page move)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
=Binary Compatibility Workarounds=
[[Category:Developing_Qt::Guidelines]]


This page describes some workarounds for keeping binary compatibility in patch releases.
This page describes some workarounds for keeping binary compatibility in patch releases. You should read the KDE reference: [https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B Binary Compatibility Issues with C++].


You should read the <span class="caps">KDE</span> reference: http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++
Specifically, the d-pointer technique is explained in much detail in [[D-Pointer|D-Pointer: What Private Implementation is and how it works]].


==Declaring a slot for private classes (d-pointer)==
== Declaring a slot for private classes (d-pointer) ==


Use a Q_PRIVATE_SLOT:
Use a Q_PRIVATE_SLOT:
<code lang="cpp">
class A: public QObject
{
Q_OBJECT
private:
Q_PRIVATE_SLOT(d_func(), void myPrivateSlot())
};
/* in .cpp file */
void APrivate::myPrivateSlot() {…}
#include "moc_a.cpp"
</code>


Pitfalls to avoid:
Pitfalls to avoid:


* Don’t include `a.moc`, but `moc_a.cpp` in your .cpp file
* ''' Don't include `a.moc`, but `moc_a.cpp` in your .cpp file
* Q_PRIVATE_SLOT takes the complete signature of the private slot, not just its name
* Q_PRIVATE_SLOT takes the complete signature of the private slot, not just its name
===Categories:===
* [[:Category:Developing Qt|Developing_Qt]]

Latest revision as of 13:43, 25 August 2017


This page describes some workarounds for keeping binary compatibility in patch releases. You should read the KDE reference: Binary Compatibility Issues with C++.

Specifically, the d-pointer technique is explained in much detail in D-Pointer: What Private Implementation is and how it works.

Declaring a slot for private classes (d-pointer)

Use a Q_PRIVATE_SLOT:

 class A: public QObject
 {
 Q_OBJECT
 
 private:
 Q_PRIVATE_SLOT(d_func(), void myPrivateSlot())
 };

/* in .cpp file */

 void APrivate::myPrivateSlot() {}

 #include "moc_a.cpp"

Pitfalls to avoid:

  • Don't include `a.moc`, but `moc_a.cpp` in your .cpp file
  • Q_PRIVATE_SLOT takes the complete signature of the private slot, not just its name