Skip to content

Instantly share code, notes, and snippets.

@hostilefork
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hostilefork/61cd8083bb958272caca to your computer and use it in GitHub Desktop.
Save hostilefork/61cd8083bb958272caca to your computer and use it in GitHub Desktop.
// Test for http://stackoverflow.com/questions/8455887/stack-object-qt-signal-and-parameter-as-reference/
#include <iostream>
#include <QCoreApplication>
#include <QTimer>
#include "param.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qRegisterMetaType<Param>("CopyConstructorParam");
Test t;
QTimer::singleShot(200, &t, &Test::run);
return a.exec();
}
// 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, &Test::transmit,
this, &Test::receive,
Qt::QueuedConnection
);
}
}
void run() {
Param p;
std::cout << "transmitting with " << &p << " as parameter\n";
emit transmit(&p);
}
signals:
void transmit(Param * p);
public slots:
void receive(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