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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • util
qtest_kde.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2006 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "qtest_kde.h"
20 
21 // A signal spy which exits the event loop when the signal is called,
22 // and remembers that the signal was emitted.
23 class KDESignalSpy : public QObject
24 {
25  Q_OBJECT
26 public:
27  KDESignalSpy(QObject *obj, const char *signal, int timeout)
28  : QObject(0), m_obj(obj), m_emitted(false)
29  {
30  connect(obj, signal, this, SLOT(slotSignalEmitted()));
31  if (timeout > 0) {
32  QObject::connect(&m_timer, SIGNAL(timeout()), &m_loop, SLOT(quit()));
33  m_timer.setSingleShot(true);
34  m_timer.start(timeout);
35  }
36  m_loop.exec();
37  }
38  bool signalEmitted() const { return m_emitted; }
39 
40 private Q_SLOTS:
41  void slotSignalEmitted()
42  {
43  m_emitted = true;
44  disconnect(m_obj, 0, this, 0);
45  m_timer.stop();
46  m_loop.quit();
47  }
48 private:
49  QObject* m_obj;
50  bool m_emitted;
51  QEventLoop m_loop;
52  QTimer m_timer;
53 };
54 
55 // Unit test for this code: tests/kglobaltest.cpp
56 
57 bool QTest::kWaitForSignal(QObject *obj, const char *signal, int timeout )
58 {
59  KDESignalSpy spy(obj, signal, timeout);
60  return spy.signalEmitted();
61 }
62 
63 #include "qtest_kde.moc"
timeout
int timeout
Definition: kkernel_mac.cpp:46
QObject
QTest::kWaitForSignal
bool kWaitForSignal(QObject *obj, const char *signal, int timeout=0)
Starts an event loop that runs until the given signal is received.
Definition: qtest_kde.cpp:57
qtest_kde.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal