我有一个(有点)简单的程序,可以创建新线程,每个连接一个套接字:
void TelnetServer::incomingConnection(qintptr socketDescriptor)
{
TelnetConnection *thread = new TelnetConnection(socketDescriptor);
connect(thread, SIGNAL(shutdownRequested()), m_controller, SLOT(shutdown()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
创建新线程后,我向 qDebug 输出创建 QThreads (TelnetConnection) 的父级的所有子级的列表,如下所示:
QList<QObject*> activeTelnetConnections = m_telnetserver->findChildren <QObject *> (); // Find all QThreads that children of telnetserver
qDebug() << "Children: " << activeTelnetConnections;
由于我的 QThreads 从 Qobject 下降,我希望看到 QThreads 的列表等等。但是,我找不到 Qthreads!这就是我所看到的:
Children: (QNativeSocketEngine(0x7eb880) , QSocketNotifier(0x7ea5f0) )
为什么我看不到子线程?这是否意味着线程不再与父对象关联?或者我在这里做错了什么......