Skip to content

Instantly share code, notes, and snippets.

@cgmb
Forked from hostilefork/main.cpp
Last active August 29, 2015 14:19
Show Gist options
  • Save cgmb/a000fdb907995e0d727e to your computer and use it in GitHub Desktop.
Save cgmb/a000fdb907995e0d727e to your computer and use it in GitHub Desktop.
#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();
}
// 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