Results 1 to 12 of 12

Thread: Signal/Slots with PIMPL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Signal/Slots with PIMPL

    You can declare it the cpp file but then add
    For that you first need to have the moc file, which is generated by the moc compiler...
    If you want to use Q_OBJECT you will have first to have this in a header, run moc on it, and then add #include "foo.moc".
    AFAIK at least.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Signal/Slots with PIMPL

    On my side this works perfect:

    Qt Code:
    1. //main.cpp
    2. #include <QtCore>
    3. #include "outer.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9. Outer o;
    10. QTimer::singleShot(1000, &a, SLOT(quit()));
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //outer.h
    2. #ifndef OUTER_H
    3. #define OUTER_H
    4.  
    5. #include <QObject>
    6. class Inner;
    7.  
    8. class Outer : public QObject
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit Outer(QObject *parent = 0);
    13. public Q_SLOTS:
    14. void mySlot();
    15. private:
    16. Inner* m_inner;
    17. };
    18.  
    19. #endif // OUTER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //outer.cpp
    2. #include "outer.h"
    3.  
    4. #include <QtCore>
    5.  
    6.  
    7. class Inner : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. Inner(QObject *p) : QObject(p) {}
    12. Q_SIGNALS:
    13. void mySignal();
    14. public:
    15. void emitMySignal() {Q_EMIT mySignal();}
    16. };
    17.  
    18. Outer::Outer(QObject *parent) :
    19. QObject(parent)
    20. {
    21. m_inner = new Inner(this);
    22. connect(m_inner, SIGNAL(mySignal()), this, SLOT(mySlot()));
    23. m_inner->emitMySignal();
    24. }
    25.  
    26. void Outer::mySlot()
    27. {
    28. qWarning() << Q_FUNC_INFO;
    29. }
    30.  
    31. #include "outer.moc"
    To copy to clipboard, switch view to plain text mode 

    And don't forget to rerun qmake...

Similar Threads

  1. Doubts on signal and slots
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 27th June 2011, 10:32
  2. Signal/Slots, Where can i use it?
    By Tio in forum Newbie
    Replies: 2
    Last Post: 25th May 2010, 01:36
  3. Signal and Slots
    By waynew in forum Newbie
    Replies: 3
    Last Post: 20th November 2009, 03:50
  4. signal and slots
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 16th October 2007, 08:31
  5. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 10:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.