-
-
Save cgmb/a000fdb907995e0d727e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <QCoreApplication> | |
#include <QTimer> | |
#include "param.h" | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
// qRegisterMetaType<Param>("CopyConstructorParam"); | |
qRegisterMetaType<Param>("Param"); | |
Test t; | |
QTimer::singleShot(200, &t, SLOT(run())); | |
return a.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test for http://stackoverflow.com/questions/8455887/stack-object-qt-signal-and-parameter-as-reference/ | |
#ifndef PARAM_H | |
#define PARAM_H | |
#include <iostream> | |
#include <QCoreApplication> | |
#include <QDebug> | |
class Param { | |
public: | |
Param () {} | |
Param (Param const &) { | |
std::cout << "Calling Copy Constructor\n"; | |
} | |
}; | |
class Test : public QObject { | |
Q_OBJECT | |
public: | |
Test () { | |
for (int index = 0; index < 3; index++) { | |
connect( | |
this, SIGNAL(transmit(Param)), | |
this, SLOT(receive(Param)), | |
Qt::QueuedConnection | |
); | |
} | |
} | |
public slots: | |
void run() { | |
Param p; | |
std::cout << "transmitting with " << &p << " as parameter\n"; | |
emit transmit(p); | |
} | |
signals: | |
void transmit(const Param& p); | |
public slots: | |
void receive(const Param& p) { | |
std::cout << "receive called with " << &p << " as parameter\n"; | |
} | |
}; | |
#endif // PARAM_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment