Hello,
first of all i want to say hello to this great forum 
Here my problem (I tried to find it on the internet, but I did not have luck):
If i connect a simple slot (only writes a string on the console) to a signals and emit this signal a lot of times, the program's memory usage increases.
But only, if i connect the signal to the slot with Qt::QueuedConnection. If it is direct connected, the memory sticks at the same size, as if i would never emit the signal.
Why does this happens?
Thank you and good night 
Here my code:
main.cpp
#include <QtCore/QCoreApplication>
#include "a.h"
int main(int argc, char *argv[]) {
A a;
QObject::connect(&a,
SIGNAL(testSig
()),
&a,
SLOT(testSlot
())/*, Qt::QueuedConnection*/);
for (int i = 0; i < 50000; ++i) a.test();
return app.exec();
}
#include <QtCore/QCoreApplication>
#include "a.h"
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
A a;
QObject::connect(&a, SIGNAL(testSig()), &a, SLOT(testSlot())/*, Qt::QueuedConnection*/);
for (int i = 0; i < 50000; ++i) a.test();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
a.h
#ifndef A_H
#define A_H
#include <QObject>
Q_OBJECT
public:
A();
void test();
public slots:
void testSlot();
signals:
void testSig();
};
#endif // A_H
#ifndef A_H
#define A_H
#include <QObject>
class A : public QObject {
Q_OBJECT
public:
A();
void test();
public slots:
void testSlot();
signals:
void testSig();
};
#endif // A_H
To copy to clipboard, switch view to plain text mode
a.cpp
#include "a.h"
A::A() {
}
void A::testSlot() {
qDebug("hi");
}
void A::test() {
emit testSig();
}
#include "a.h"
A::A() {
}
void A::testSlot() {
qDebug("hi");
}
void A::test() {
emit testSig();
}
To copy to clipboard, switch view to plain text mode
Bookmarks