It does not start it in a second thread. AFAIK, it will be either a direct call or queued for handling by default. The situation also depends on how you are managing your threads.
There are several connection types you can choose from, but usually, the default (direct or queued) should be fine.
I will show you two examples to demonstrate that it also depends on what exactly emits the signal.
Case 1 (Emitted by the slot being executed)
main.cpp
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = 0) : QObject(parent), counter(0)
{
connect(this, SIGNAL(mySignal()),
this, SLOT(mySlot()), Qt::QueuedConnection);
}
signals:
void mySignal();
public slots:
void mySlot()
{
if (counter >= 2) return;
++counter;
qDebug() << "mySlot started";
emit mySignal();
QThread::msleep(1000);
qDebug() << "mySlot quit";
}
private:
int counter;
};
#include "main.moc"
int main(int argc, char **argv)
{
QCoreApplication application(argc, argv);
MyClass myObject;
myObject.mySlot();
return application.exec();
}
main.pro
TEMPLATE = app
TARGET = test
QT = core
SOURCES += main.cpp
Build and Run
moc -o main.moc main.cpp && qmake && make && ./test
Output
mySlot started
mySlot quit
mySlot started
mySlot quit
You would get the following output without queued connection to indicate that it would be a direct call in the middle of the slot execution in my example:
mySlot started
mySlot started
mySlot quit
mySlot quit
Case 2 (not emitted by the slot being executed)
main.cpp
#include <QObject>
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
#include <QTimer>
class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = 0) : QObject(parent), counter(0), timer(new QTimer(this))
{
// Note: there is no need for queued connection in this case
connect(this, SIGNAL(mySignal()), this, SLOT(mySlot()));
connect(timer, SIGNAL(timeout()), this, SLOT(mySlot()));
timer->setSingleShot(true);
timer->start(200);
}
signals:
void mySignal();
public slots:
void mySlot()
{
++counter;
qDebug() << "mySlot started" << counter;
QThread::msleep(1000);
qDebug() << "mySlot quit" << counter;
}
private:
int counter;
QTimer *timer;
};
#include "main.moc"
int main(int argc, char **argv)
{
QCoreApplication application(argc, argv);
MyClass myObject;
myObject.mySlot();
return application.exec();
}
main.pro
TEMPLATE = app
TARGET = test
QT = core
SOURCES += main.cpp
Build and Run
moc -o main.moc main.cpp && qmake && make && ./test
Output
mySlot started 1
mySlot quit 1
mySlot started 2
mySlot quit 2