summaryrefslogtreecommitdiffstats
path: root/examples/threads
diff options
context:
space:
mode:
Diffstat (limited to 'examples/threads')
-rw-r--r--examples/threads/mandelbrot/main.cpp4
-rw-r--r--examples/threads/mandelbrot/mandelbrot.desktop11
-rw-r--r--examples/threads/mandelbrot/mandelbrot.pro1
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.cpp18
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.h30
-rw-r--r--examples/threads/queuedcustomtype/main.cpp4
-rw-r--r--examples/threads/queuedcustomtype/queuedcustomtype.desktop11
-rw-r--r--examples/threads/queuedcustomtype/queuedcustomtype.pro10
-rw-r--r--examples/threads/semaphores/semaphores.cpp81
-rw-r--r--examples/threads/semaphores/semaphores.desktop11
-rw-r--r--examples/threads/semaphores/semaphores.pro6
-rw-r--r--examples/threads/threads.pro1
-rw-r--r--examples/threads/waitconditions/waitconditions.cpp132
-rw-r--r--examples/threads/waitconditions/waitconditions.desktop11
-rw-r--r--examples/threads/waitconditions/waitconditions.pro5
15 files changed, 272 insertions, 64 deletions
diff --git a/examples/threads/mandelbrot/main.cpp b/examples/threads/mandelbrot/main.cpp
index 610534d4a3..5211c2051c 100644
--- a/examples/threads/mandelbrot/main.cpp
+++ b/examples/threads/mandelbrot/main.cpp
@@ -47,7 +47,11 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MandelbrotWidget widget;
+#if defined(Q_WS_S60)
+ widget.showMaximized();
+#else
widget.show();
+#endif
return app.exec();
}
//! [0]
diff --git a/examples/threads/mandelbrot/mandelbrot.desktop b/examples/threads/mandelbrot/mandelbrot.desktop
new file mode 100644
index 0000000000..3e70e1aa06
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrot.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Mandelbrot
+Exec=/opt/usr/bin/mandelbrot
+Icon=mandelbrot
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/threads/mandelbrot/mandelbrot.pro b/examples/threads/mandelbrot/mandelbrot.pro
index c19a9bd1aa..0e053af072 100644
--- a/examples/threads/mandelbrot/mandelbrot.pro
+++ b/examples/threads/mandelbrot/mandelbrot.pro
@@ -14,3 +14,4 @@ INSTALLS += target sources
symbian: CONFIG += qt_example
QT += widgets
+maemo5: CONFIG += qt_example
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.cpp b/examples/threads/mandelbrot/mandelbrotwidget.cpp
index b4233538d9..7cee70f547 100644
--- a/examples/threads/mandelbrot/mandelbrotwidget.cpp
+++ b/examples/threads/mandelbrot/mandelbrotwidget.cpp
@@ -44,6 +44,7 @@
#include "mandelbrotwidget.h"
+
//! [0]
const double DefaultCenterX = -0.637011f;
const double DefaultCenterY = -0.0395159f;
@@ -72,6 +73,21 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent)
setCursor(Qt::CrossCursor);
#endif
resize(550, 400);
+
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+ ZoomButton *zoomIn = new ZoomButton(tr("Zoom In"), ZoomInFactor, this);
+ ZoomButton *zoomOut = new ZoomButton(tr("Zoom Out"), ZoomOutFactor, this);
+
+ QGridLayout *layout = new QGridLayout(this);
+ layout->addWidget(zoomIn, 0, 1);
+ layout->addWidget(zoomOut, 1, 1);
+ layout->setColumnStretch(0, 10);
+ layout->setRowStretch(2, 10);
+ setLayout(layout);
+
+ connect(zoomIn, SIGNAL(zoom(double)), this, SLOT(zoom(double)));
+ connect(zoomOut, SIGNAL(zoom(double)), this, SLOT(zoom(double)));
+#endif
}
//! [1]
@@ -113,6 +129,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
}
//! [8] //! [9]
+#if !defined(Q_WS_S60) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR)
QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. "
"Press and hold left mouse button to scroll.");
QFontMetrics metrics = painter.fontMetrics();
@@ -125,6 +142,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
painter.setPen(Qt::white);
painter.drawText((width() - textWidth) / 2,
metrics.leading() + metrics.ascent(), text);
+#endif
}
//! [9]
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.h b/examples/threads/mandelbrot/mandelbrotwidget.h
index 5af3a8dffd..53bbeb6469 100644
--- a/examples/threads/mandelbrot/mandelbrotwidget.h
+++ b/examples/threads/mandelbrot/mandelbrotwidget.h
@@ -43,9 +43,35 @@
#include <QPixmap>
#include <QWidget>
-
#include "renderthread.h"
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
+#include <QPushButton>
+
+class ZoomButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ ZoomButton(const QString &text, double zoomFactor, QWidget *parent = NULL)
+ : QPushButton(text, parent), m_ZoomFactor(zoomFactor)
+ {
+ connect(this, SIGNAL(clicked()), this, SLOT(handleClick()));
+ }
+
+signals:
+ void zoom(double zoomFactor);
+
+private slots:
+ void handleClick()
+ {
+ emit zoom(m_ZoomFactor);
+ }
+
+private:
+ const double m_ZoomFactor;
+};
+#endif
+
//! [0]
class MandelbrotWidget : public QWidget
{
@@ -65,9 +91,9 @@ protected:
private slots:
void updatePixmap(const QImage &image, double scaleFactor);
+ void zoom(double zoomFactor);
private:
- void zoom(double zoomFactor);
void scroll(int deltaX, int deltaY);
RenderThread thread;
diff --git a/examples/threads/queuedcustomtype/main.cpp b/examples/threads/queuedcustomtype/main.cpp
index d70a88a095..356352a326 100644
--- a/examples/threads/queuedcustomtype/main.cpp
+++ b/examples/threads/queuedcustomtype/main.cpp
@@ -119,7 +119,11 @@ int main(int argc, char *argv[])
qsrand(QTime::currentTime().elapsed());
Window window;
+#if defined(Q_WS_S60)
+ window.showMaximized();
+#else
window.show();
+#endif
window.loadImage(createImage(256, 256));
//! [main finish]
diff --git a/examples/threads/queuedcustomtype/queuedcustomtype.desktop b/examples/threads/queuedcustomtype/queuedcustomtype.desktop
new file mode 100644
index 0000000000..fa5ed7aa35
--- /dev/null
+++ b/examples/threads/queuedcustomtype/queuedcustomtype.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Queued Custom Type
+Exec=/opt/usr/bin/queuedcustomtype
+Icon=queuedcustomtype
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/threads/queuedcustomtype/queuedcustomtype.pro b/examples/threads/queuedcustomtype/queuedcustomtype.pro
index f26ab6cde5..fc8d4d7bc6 100644
--- a/examples/threads/queuedcustomtype/queuedcustomtype.pro
+++ b/examples/threads/queuedcustomtype/queuedcustomtype.pro
@@ -6,3 +6,13 @@ SOURCES = main.cpp \
renderthread.cpp \
window.cpp
QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/threads/mandelbrot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mandelbrot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/threads/mandelbrot
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
+
diff --git a/examples/threads/semaphores/semaphores.cpp b/examples/threads/semaphores/semaphores.cpp
index 88630def09..3632895c61 100644
--- a/examples/threads/semaphores/semaphores.cpp
+++ b/examples/threads/semaphores/semaphores.cpp
@@ -38,13 +38,18 @@
**
****************************************************************************/
-#include <QtCore>
+#include <QtGui>
#include <stdio.h>
#include <stdlib.h>
//! [0]
+#ifdef Q_WS_S60
+const int DataSize = 300;
+#else
const int DataSize = 100000;
+#endif
+
const int BufferSize = 8192;
char buffer[BufferSize];
@@ -57,43 +62,70 @@ class Producer : public QThread
//! [1] //! [2]
{
public:
- void run();
-};
-
-void Producer::run()
-{
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
- for (int i = 0; i < DataSize; ++i) {
- freeBytes.acquire();
- buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
- usedBytes.release();
+ void run()
+ {
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ for (int i = 0; i < DataSize; ++i) {
+ freeBytes.acquire();
+ buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
+ usedBytes.release();
+ }
}
-}
+};
//! [2]
//! [3]
class Consumer : public QThread
//! [3] //! [4]
{
+ Q_OBJECT
public:
- void run();
-};
-
-void Consumer::run()
-{
- for (int i = 0; i < DataSize; ++i) {
- usedBytes.acquire();
- fprintf(stderr, "%c", buffer[i % BufferSize]);
- freeBytes.release();
+ void run()
+ {
+ for (int i = 0; i < DataSize; ++i) {
+ usedBytes.acquire();
+ #ifdef Q_WS_S60
+ QString text(buffer[i % BufferSize]);
+ freeBytes.release();
+ emit stringConsumed(text);
+ #else
+ fprintf(stderr, "%c", buffer[i % BufferSize]);
+ freeBytes.release();
+ #endif
+ }
+ fprintf(stderr, "\n");
}
- fprintf(stderr, "\n");
-}
+
+signals:
+ void stringConsumed(const QString &text);
+
+protected:
+ bool finish;
+};
//! [4]
//! [5]
int main(int argc, char *argv[])
//! [5] //! [6]
{
+#ifdef Q_WS_S60
+ // Self made console for Symbian
+ QApplication app(argc, argv);
+ QPlainTextEdit console;
+ console.setReadOnly(true);
+ console.setTextInteractionFlags(Qt::NoTextInteraction);
+ console.showMaximized();
+
+ Producer producer;
+ Consumer consumer;
+
+ QObject::connect(&consumer, SIGNAL(stringConsumed(const QString&)), &console, SLOT(insertPlainText(QString)), Qt::BlockingQueuedConnection);
+
+ producer.start();
+ consumer.start();
+
+ app.exec();
+#else
QCoreApplication app(argc, argv);
Producer producer;
Consumer consumer;
@@ -102,5 +134,8 @@ int main(int argc, char *argv[])
producer.wait();
consumer.wait();
return 0;
+#endif
}
//! [6]
+
+#include "semaphores.moc"
diff --git a/examples/threads/semaphores/semaphores.desktop b/examples/threads/semaphores/semaphores.desktop
new file mode 100644
index 0000000000..a7dc46722f
--- /dev/null
+++ b/examples/threads/semaphores/semaphores.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Semaphores
+Exec=/opt/usr/bin/semaphores
+Icon=semaphores
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/threads/semaphores/semaphores.pro b/examples/threads/semaphores/semaphores.pro
index 185a051986..96ab3a525f 100644
--- a/examples/threads/semaphores/semaphores.pro
+++ b/examples/threads/semaphores/semaphores.pro
@@ -1,5 +1,6 @@
SOURCES += semaphores.cpp
-QT = core
+QT = core gui
+
CONFIG -= app_bundle
CONFIG += console
@@ -10,3 +11,6 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/semaphores
INSTALLS += target sources
symbian: CONFIG += qt_example
+maemo5: CONFIG += qt_example
+
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/threads/threads.pro b/examples/threads/threads.pro
index 33a9d95770..9bdf900f5b 100644
--- a/examples/threads/threads.pro
+++ b/examples/threads/threads.pro
@@ -12,3 +12,4 @@ INSTALLS += target sources
symbian: CONFIG += qt_example
QT += widgets
+maemo5: CONFIG += qt_example
diff --git a/examples/threads/waitconditions/waitconditions.cpp b/examples/threads/waitconditions/waitconditions.cpp
index 5c8cb7149f..0063db5b91 100644
--- a/examples/threads/waitconditions/waitconditions.cpp
+++ b/examples/threads/waitconditions/waitconditions.cpp
@@ -38,13 +38,18 @@
**
****************************************************************************/
-#include <QtCore>
+#include <QtGui>
#include <stdio.h>
#include <stdlib.h>
//! [0]
+#ifdef Q_WS_S60
+const int DataSize = 300;
+#else
const int DataSize = 100000;
+#endif
+
const int BufferSize = 8192;
char buffer[BufferSize];
@@ -59,60 +64,110 @@ class Producer : public QThread
//! [1] //! [2]
{
public:
- void run();
-};
+ Producer(QObject *parent = NULL) : QThread(parent)
+ {
+ }
-void Producer::run()
-{
- qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
-
- for (int i = 0; i < DataSize; ++i) {
- mutex.lock();
- if (numUsedBytes == BufferSize)
- bufferNotFull.wait(&mutex);
- mutex.unlock();
-
- buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
-
- mutex.lock();
- ++numUsedBytes;
- bufferNotEmpty.wakeAll();
- mutex.unlock();
+ void run()
+ {
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ for (int i = 0; i < DataSize; ++i) {
+ mutex.lock();
+ if (numUsedBytes == BufferSize)
+ bufferNotFull.wait(&mutex);
+ mutex.unlock();
+
+ buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
+
+ mutex.lock();
+ ++numUsedBytes;
+ bufferNotEmpty.wakeAll();
+ mutex.unlock();
+ }
}
-}
+};
//! [2]
//! [3]
class Consumer : public QThread
//! [3] //! [4]
{
+ Q_OBJECT
public:
- void run();
+ Consumer(QObject *parent = NULL) : QThread(parent)
+ {
+ }
+
+ void run()
+ {
+ for (int i = 0; i < DataSize; ++i) {
+ mutex.lock();
+ if (numUsedBytes == 0)
+ bufferNotEmpty.wait(&mutex);
+ mutex.unlock();
+
+ #ifdef Q_WS_S60
+ emit stringConsumed(QString(buffer[i % BufferSize]));
+ #else
+ fprintf(stderr, "%c", buffer[i % BufferSize]);
+ #endif
+
+ mutex.lock();
+ --numUsedBytes;
+ bufferNotFull.wakeAll();
+ mutex.unlock();
+ }
+ fprintf(stderr, "\n");
+ }
+
+signals:
+ void stringConsumed(const QString &text);
};
+//! [4]
-void Consumer::run()
+#ifdef Q_WS_S60
+class PlainTextEdit : public QPlainTextEdit
{
- for (int i = 0; i < DataSize; ++i) {
- mutex.lock();
- if (numUsedBytes == 0)
- bufferNotEmpty.wait(&mutex);
- mutex.unlock();
-
- fprintf(stderr, "%c", buffer[i % BufferSize]);
-
- mutex.lock();
- --numUsedBytes;
- bufferNotFull.wakeAll();
- mutex.unlock();
+ Q_OBJECT
+public:
+ PlainTextEdit(QWidget *parent = NULL) : QPlainTextEdit(parent), producer(NULL), consumer(NULL)
+ {
+ setTextInteractionFlags(Qt::NoTextInteraction);
+
+ producer = new Producer(this);
+ consumer = new Consumer(this);
+
+ QObject::connect(consumer, SIGNAL(stringConsumed(const QString &)), SLOT(insertPlainText(const QString &)), Qt::BlockingQueuedConnection);
+
+ QTimer::singleShot(0, this, SLOT(startThreads()));
}
- fprintf(stderr, "\n");
-}
-//! [4]
+
+protected:
+ Producer *producer;
+ Consumer *consumer;
+
+protected slots:
+ void startThreads()
+ {
+ producer->start();
+ consumer->start();
+ }
+};
+#endif
//! [5]
int main(int argc, char *argv[])
//! [5] //! [6]
{
+#ifdef Q_WS_S60
+ QApplication app(argc, argv);
+
+ PlainTextEdit console;
+ console.showMaximized();
+
+ return app.exec();
+#else
QCoreApplication app(argc, argv);
Producer producer;
Consumer consumer;
@@ -121,5 +176,8 @@ int main(int argc, char *argv[])
producer.wait();
consumer.wait();
return 0;
+#endif
}
//! [6]
+
+#include "waitconditions.moc"
diff --git a/examples/threads/waitconditions/waitconditions.desktop b/examples/threads/waitconditions/waitconditions.desktop
new file mode 100644
index 0000000000..4fbc3047d7
--- /dev/null
+++ b/examples/threads/waitconditions/waitconditions.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Wait Conditions
+Exec=/opt/usr/bin/waitconditions
+Icon=waitconditions
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/threads/waitconditions/waitconditions.pro b/examples/threads/waitconditions/waitconditions.pro
index 53350d2dae..e326afa081 100644
--- a/examples/threads/waitconditions/waitconditions.pro
+++ b/examples/threads/waitconditions/waitconditions.pro
@@ -3,8 +3,8 @@
######################################################################
TEMPLATE = app
+QT = core gui
CONFIG -= moc app_bundle
-QT -= gui
DEPENDPATH += .
INCLUDEPATH += .
@@ -19,3 +19,6 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/waitconditions
INSTALLS += target sources
symbian: CONFIG += qt_example
+maemo5: CONFIG += qt_example
+
+simulator: warning(This example might not fully work on Simulator platform)