diff options
Diffstat (limited to 'sandbox/messaging-to-self')
-rw-r--r-- | sandbox/messaging-to-self/main.cpp | 20 | ||||
-rw-r--r-- | sandbox/messaging-to-self/messaging-to-self.pro | 12 | ||||
-rw-r--r-- | sandbox/messaging-to-self/myobject.h | 35 | ||||
-rw-r--r-- | sandbox/messaging-to-self/mythread.h | 32 | ||||
-rw-r--r-- | sandbox/messaging-to-self/queuedinvoker.cpp | 35 | ||||
-rw-r--r-- | sandbox/messaging-to-self/queuedinvoker.h | 29 |
6 files changed, 0 insertions, 163 deletions
diff --git a/sandbox/messaging-to-self/main.cpp b/sandbox/messaging-to-self/main.cpp deleted file mode 100644 index aafda83c..00000000 --- a/sandbox/messaging-to-self/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <QCoreApplication> -#include <QDebug> -#include <QThread> -#include "myobject.h" -#include "mythread.h" - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - - qDebug() << "main thread:" << QThread::currentThread(); - - MyObject a; - MyThread t(&a); - t.start(); - -// sleep(1); - - return app.exec(); -} diff --git a/sandbox/messaging-to-self/messaging-to-self.pro b/sandbox/messaging-to-self/messaging-to-self.pro deleted file mode 100644 index bafbb027..00000000 --- a/sandbox/messaging-to-self/messaging-to-self.pro +++ /dev/null @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Mon Jun 15 11:49:08 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += myobject.h mythread.h queuedinvoker.h -SOURCES += main.cpp queuedinvoker.cpp diff --git a/sandbox/messaging-to-self/myobject.h b/sandbox/messaging-to-self/myobject.h deleted file mode 100644 index 155ebf3b..00000000 --- a/sandbox/messaging-to-self/myobject.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef MYOBJECT_H -#define MYOBJECT_H - -#include "queuedinvoker.h" -#include <QDebug> -#include <QThread> - -class MyObject : public QueuedInvoker -{ - Q_OBJECT - -private: - int x; - -public: - MyObject() : x(0) - { - } - - Q_INVOKABLE void five() - { - qDebug() << "MyObject::five" << QThread::currentThread() << ++x; - } - Q_INVOKABLE void six() - { - qDebug() << "MyObject::six" << QThread::currentThread() << ++x; - } - Q_INVOKABLE void seven() - { - qDebug() << "MyObject::seven" << QThread::currentThread() << ++x; - } -}; -#endif - - diff --git a/sandbox/messaging-to-self/mythread.h b/sandbox/messaging-to-self/mythread.h deleted file mode 100644 index 4170ccf8..00000000 --- a/sandbox/messaging-to-self/mythread.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MYTHREAD_H -#define MYTHREAD_H - -#include <QThread> -#include <QDebug> -#include "myobject.h" - -class MyThread : public QThread -{ - Q_OBJECT - -private: - MyObject *obj; - -public: - MyThread(MyObject *obj) : obj(obj) - { - } - -protected: - void run() - { - qDebug() << QThread::currentThread(); - obj->queueOnce("five"); - obj->queueOnce("six"); - obj->queueOnce("five"); - obj->queueOnce("five"); - obj->queueOnce("six"); - obj->queueOnce("seven"); - } -}; -#endif diff --git a/sandbox/messaging-to-self/queuedinvoker.cpp b/sandbox/messaging-to-self/queuedinvoker.cpp deleted file mode 100644 index 85dbb7d1..00000000 --- a/sandbox/messaging-to-self/queuedinvoker.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "queuedinvoker.h" - -#include <QMetaObject> -#include <QThread> -#include <QDebug> -#include <QMutexLocker> - -QueuedInvoker::QueuedInvoker() -{ - connect(this, SIGNAL(queuedCall(const char *)), - this, SLOT(onQueuedCall(const char *)), - Qt::QueuedConnection); -} - -void QueuedInvoker::onQueuedCall(const char *method) -{ - QMutexLocker locker(&callQueueLock); - callQueue.remove(method); - qDebug() << "Hope that i'm in the main loop" << QThread::currentThread(); - locker.unlock(); - if (!QMetaObject::invokeMethod(this, method, Qt::DirectConnection)) { - qFatal(" *****************\n" - "Erroneous usage of queueOnce(%s)\n" - " *****************\n", method); - } -} - -void QueuedInvoker::queueOnce(const char *method) -{ - QMutexLocker locker(&callQueueLock); - if (!callQueue.contains(method)) { - emit queuedCall(method); - callQueue.insert(method); - } -} diff --git a/sandbox/messaging-to-self/queuedinvoker.h b/sandbox/messaging-to-self/queuedinvoker.h deleted file mode 100644 index 8f81f26e..00000000 --- a/sandbox/messaging-to-self/queuedinvoker.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef QUEUEDINVOKER_H -#define QUEUEDINVOKER_H - -#include <QObject> -#include <QMutex> -#include <QSet> -#include <QString> - -class QueuedInvoker : public QObject -{ - Q_OBJECT - -public: - QueuedInvoker(); - -private slots: - void onQueuedCall(const char *method); - -signals: - void queuedCall(const char *method); - -public: - void queueOnce(const char *method); - -private: - QMutex callQueueLock; - QSet<QString> callQueue; -}; -#endif |