• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

qtest_kde.cpp

Go to the documentation of this file.
00001 #include "qtest_kde.h"
00002 
00003 // A signal spy which exits the event loop when the signal is called,
00004 // and remembers that the signal was emitted.
00005 class KDESignalSpy : public QObject
00006 {
00007     Q_OBJECT
00008 public:
00009     KDESignalSpy(QObject *obj, const char *signal, int timeout)
00010         : QObject(0), m_obj(obj), m_emitted(false)
00011     {
00012         connect(obj, signal, this, SLOT(slotSignalEmitted()));
00013         if (timeout > 0) {
00014             QObject::connect(&m_timer, SIGNAL(timeout()), &m_loop, SLOT(quit()));
00015             m_timer.setSingleShot(true);
00016             m_timer.start(timeout);
00017         }
00018         m_loop.exec();
00019     }
00020     bool signalEmitted() const { return m_emitted; }
00021 
00022 private Q_SLOTS:
00023     void slotSignalEmitted()
00024     {
00025         m_emitted = true;
00026         disconnect(m_obj, 0, this, 0);
00027         m_timer.stop();
00028         m_loop.quit();
00029     }
00030 private:
00031     QObject* m_obj;
00032     bool m_emitted;
00033     QEventLoop m_loop;
00034     QTimer m_timer;
00035 };
00036 
00037 // Unit test for this code: tests/kglobaltest.cpp
00038 
00039 bool QTest::kWaitForSignal(QObject *obj, const char *signal, int timeout )
00040 {
00041     KDESignalSpy spy(obj, signal, timeout);
00042     return spy.signalEmitted();
00043 }
00044 
00045 #include "qtest_kde.moc"

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal