summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond.kjernasen@nokia.com>2010-04-30 13:33:26 (GMT)
committerTrond Kjernåsen <trond.kjernasen@nokia.com>2010-07-02 10:25:18 (GMT)
commit778ee2e9a2db3f3a1bc9d282356798baa77f6efd (patch)
tree1d4ef0896a977edb9262aa9146a12117ea7be988
parentdecda7ea196b610ab1d70345cb89a4a67bfd1e91 (diff)
downloadQt-778ee2e9a2db3f3a1bc9d282356798baa77f6efd.zip
Qt-778ee2e9a2db3f3a1bc9d282356798baa77f6efd.tar.gz
Qt-778ee2e9a2db3f3a1bc9d282356798baa77f6efd.tar.bz2
Add an application attribute to control XInitThreads().
In order to make Xlib thread-safe XInitThreads() needs to be the first Xlib call issued. This attribute controls this behavior. Having Xlib thread-safe will most likely incur some overhead, which is why this is not done by default.
-rw-r--r--src/corelib/global/qnamespace.h1
-rw-r--r--src/corelib/global/qnamespace.qdoc4
-rw-r--r--src/gui/image/qpixmap.cpp3
-rw-r--r--src/gui/kernel/qapplication_x11.cpp3
4 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index a9c56f6..84ab567 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -530,6 +530,7 @@ public:
AA_DontUseNativeMenuBar = 6,
AA_MacDontSwapCtrlAndMeta = 7,
AA_S60DontConstructApplicationPanes = 8,
+ AA_X11InitThreads = 9,
// Add new attributes before this line
AA_AttributeCount
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 7eae3a5..ce1176d 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -170,6 +170,10 @@
whole lifetime. This attribute must be set before QApplication is
constructed.
+ \value AA_X11InitThreads Calls XInitThreads() as part of the QApplication
+ construction in order to make Xlib calls thread-safe.
+
+
\omitvalue AA_AttributeCount
*/
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index e630e80..a2b0b95 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -94,13 +94,12 @@ Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap)
static bool qt_pixmap_thread_test()
{
- return true;
if (!qApp) {
qFatal("QPixmap: Must construct a QApplication before a QPaintDevice");
return false;
}
#ifndef Q_WS_WIN
- if (qApp->thread() != QThread::currentThread()) {
+ if (!QApplication::testAttribute(Qt::AA_X11InitThreads) && qApp->thread() != QThread::currentThread()) {
qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread");
return false;
}
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index 9d5a7c0..5e212ca 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -1710,6 +1710,9 @@ void qt_init(QApplicationPrivate *priv, int,
} else {
// Qt controls everything (default)
+ if (QApplication::testAttribute(Qt::AA_X11InitThreads))
+ XInitThreads();
+
// Set application name and class
char *app_class = 0;
if (argv && argv[0]) {