On my side this works perfect:
//main.cpp
#include <QtCore>
#include "outer.h"
int main(int argc, char *argv[])
{
Outer o;
QTimer::singleShot(1000,
&a,
SLOT(quit
()));
return a.exec();
}
//main.cpp
#include <QtCore>
#include "outer.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Outer o;
QTimer::singleShot(1000, &a, SLOT(quit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
//outer.h
#ifndef OUTER_H
#define OUTER_H
#include <QObject>
class Inner;
{
Q_OBJECT
public:
explicit Outer
(QObject *parent
= 0);
public Q_SLOTS:
void mySlot();
private:
Inner* m_inner;
};
#endif // OUTER_H
//outer.h
#ifndef OUTER_H
#define OUTER_H
#include <QObject>
class Inner;
class Outer : public QObject
{
Q_OBJECT
public:
explicit Outer(QObject *parent = 0);
public Q_SLOTS:
void mySlot();
private:
Inner* m_inner;
};
#endif // OUTER_H
To copy to clipboard, switch view to plain text mode
//outer.cpp
#include "outer.h"
#include <QtCore>
{
Q_OBJECT
public:
Q_SIGNALS:
void mySignal();
public:
void emitMySignal() {Q_EMIT mySignal();}
};
{
m_inner = new Inner(this);
connect(m_inner, SIGNAL(mySignal()), this, SLOT(mySlot()));
m_inner->emitMySignal();
}
void Outer::mySlot()
{
qWarning() << Q_FUNC_INFO;
}
#include "outer.moc"
//outer.cpp
#include "outer.h"
#include <QtCore>
class Inner : public QObject
{
Q_OBJECT
public:
Inner(QObject *p) : QObject(p) {}
Q_SIGNALS:
void mySignal();
public:
void emitMySignal() {Q_EMIT mySignal();}
};
Outer::Outer(QObject *parent) :
QObject(parent)
{
m_inner = new Inner(this);
connect(m_inner, SIGNAL(mySignal()), this, SLOT(mySlot()));
m_inner->emitMySignal();
}
void Outer::mySlot()
{
qWarning() << Q_FUNC_INFO;
}
#include "outer.moc"
To copy to clipboard, switch view to plain text mode
And don't forget to rerun qmake...
Bookmarks